Kaydet (Commit) 5807952e authored tarafından Stephan Bergmann's avatar Stephan Bergmann

loplugin:redundantcast: Do warn about convoluted dynamic_cast to self

...that the compiler is free to elide anyway.  (See
4e7ffc0a "Avoid compiler eliding#redundant
dynamic_cast" and 380d6afe "Remove redundant
asserts involving dynamic_cast".)

Change-Id: I3f75154fee3e978b7ba95a5a27589417065599bd
üst 380d6afe
......@@ -682,11 +682,6 @@ bool RedundantCast::VisitCXXDynamicCastExpr(CXXDynamicCastExpr const * expr) {
if (ignoreLocation(expr)) {
return true;
}
// ignore dynamic_cast<T1>(static_cast<T1>(void*)), it's necessary
if (auto subStaticCast = dyn_cast<CXXStaticCastExpr>(expr->getSubExpr())) {
if (loplugin::TypeCheck(subStaticCast->getSubExpr()->getType()).Pointer().Void())
return true;
}
// so far this only deals with dynamic casting from T to T
auto const sub = compat::getSubExprAsWritten(expr);
auto const t1 = expr->getTypeAsWritten();
......
......@@ -333,15 +333,11 @@ void testDynamicCast() {
S1 * s1 = nullptr;
S2 * s2 = nullptr;
void * v1 = nullptr;
(void) dynamic_cast<S2 *>(s1);
(void) dynamic_cast<S1 *>(s2);
(void) dynamic_cast<S2 *>(s2); // expected-error {{redundant dynamic cast from 'S2 *' to 'S2 *' [loplugin:redundantcast]}}
(void) dynamic_cast<S3 *>(s2);
// used in some assert in vcl
(void) dynamic_cast<S1 *>(static_cast<S1*>(v1));
(void) dynamic_cast<S2 *>(static_cast<S2*>(s1)); // expected-error {{redundant dynamic cast from 'S2 *' to 'S2 *' [loplugin:redundantcast]}}
}
int main() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment