Description
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