[PATCH] D13368: [clang-tidy] add check cppcoreguidelines-pro-type-static-cast-downcast
Matthias Gehre via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 5 15:14:41 PDT 2015
mgehre marked an inline comment as done.
================
Comment at: clang-tidy/cppcoreguidelines/ProTypeStaticCastDowncastCheck.cpp:53
@@ +52,3 @@
+ } else {
+ diag(MatchedCast->getOperatorLoc(), "do not use static_cast to cast from base class to derived class.");
+ }
----------------
aaron.ballman wrote:
> What is the alternative the user should use in this instance?
The alternative is to either
1) change the program logic to not require and downcast of a non-polymorphic type
or
2) add NOLINT to notify your coworkers that this may be the spot where something goes wrong
In the end, these rules together should eliminate some classes of undefined behavior and crashes. If the application still crashes,
you should just need to look at the (hopefully few) places of NOLINT.
Anyway, I didn't make the rules. See Herb Sutters answer here: https://github.com/isocpp/CppCoreGuidelines/issues/270
http://reviews.llvm.org/D13368
More information about the cfe-commits
mailing list