Skip to content

[clang-tidy] False positive cppcoreguidelines-pro-type-static-cast-downcast when base type is not polymorphic #69414

@ChrisThrasher

Description

@ChrisThrasher

https://godbolt.org/z/ddE4bYnse

struct Base
{
    int i;
};

struct Derived : Base
{
    float f;
};

int main()
{
    Derived d1;
    Base& base = d1;
    Derived& d2 = static_cast<Derived&>(base);
}

cppcoreguidelines-pro-type-static-cast-downcast emits a warning even when the base class is not polymorphic. In the above case the static_cast is necessary to cast from base to derived since a dynamic_cast is not allowed.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions