[PATCH] D13368: [clang-tidy] add check cppcoreguidelines-pro-type-static-cast-downcast
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 2 08:54:10 PDT 2015
aaron.ballman added inline comments.
================
Comment at: clang-tidy/cppcoreguidelines/ProTypeStaticCastDowncastCheck.cpp:33
@@ +32,3 @@
+
+ SubExpr = SubExpr->IgnoreParens();
+ QualType SourceType = SubExpr->getType();
----------------
Will the type dependence check also look through parens, or should this move up a few lines?
================
Comment at: clang-tidy/cppcoreguidelines/ProTypeStaticCastDowncastCheck.cpp:42
@@ +41,3 @@
+ const CXXRecordDecl* SourceDecl;
+ if (SourceType->isPointerType())
+ SourceDecl = SourceType->getPointeeCXXRecordDecl();
----------------
No need for this or the check above -- getPointeeCXXRecordDecl() already does the right thing for references. You should be able to do:
```
if (auto *DestDecl = DestType->getPointeeCXXRecordDecl()) {
// etc
}
```
Also note that auto DestDecl isn't a good idea as it hides the fact that DestDecl is a pointer from anyone reading the code.
================
Comment at: clang-tidy/cppcoreguidelines/ProTypeStaticCastDowncastCheck.cpp:51
@@ +50,3 @@
+ if (DestDecl->isDerivedFrom(SourceDecl)) {
+ diag(MatchedCast->getOperatorLoc(), "do not use static_cast to cast from base to derived. Use "
+ "dynamic_cast instead. (C++ Core "
----------------
Formatting looks off on this; also, I don't think you need the parenthetical as that information is part of the checker name itself.
http://reviews.llvm.org/D13368
More information about the cfe-commits
mailing list