Skip to content

[clang-tidy] readability-redundant-casting false positive on inheritance #108846

@felix642

Description

@felix642

The following code snippet will trigger readability-redundant-casting and suggests removing the static_cast. Doing so would lead to a compilation failure.

class A
{
    int a;
};

class B : public A
{

};

int main()
{
    A a;
    B b = static_cast<B>(a);  // [warning: redundant explicit casting to the same type 'B' as the sub-expression, remove this casting [readability-redundant-casting]]
}

Godbolt : https://godbolt.org/z/qY1v196qG

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions