summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2014-08-16 00:53:20 +0000
committerAlexander Kornienko <alexfh@google.com>2014-08-16 00:53:20 +0000
commit08cc55dbe9fcef84b915a4f1273d035791263e55 (patch)
treefa9b58aa2d7915d55b31b17471f61bf9a4aa049c /clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
parentfe7295dcf586a2b4913fec2fd74e03e7ea7c45ec (diff)
downloadbcm5719-llvm-08cc55dbe9fcef84b915a4f1273d035791263e55.tar.gz
bcm5719-llvm-08cc55dbe9fcef84b915a4f1273d035791263e55.zip
AvoidCStyleCastsCheck: don't warn on casts in macros
llvm-svn: 215799
Diffstat (limited to 'clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
index 4b8bf140081..102b5bb9966 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -60,6 +60,12 @@ bool pointedTypesAreEqual(QualType SourceType, QualType DestType) {
void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
const auto *CastExpr = Result.Nodes.getNodeAs<CStyleCastExpr>("cast");
+ auto ParenRange = CharSourceRange::getTokenRange(CastExpr->getLParenLoc(),
+ CastExpr->getRParenLoc());
+ // Ignore casts in macros.
+ if (ParenRange.getBegin().isMacroID() || ParenRange.getEnd().isMacroID())
+ return;
+
// Casting to void is an idiomatic way to mute "unused variable" and similar
// warnings.
if (CastExpr->getTypeAsWritten()->isVoidType())
@@ -69,8 +75,6 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
CastExpr->getSubExprAsWritten()->getType().getCanonicalType();
QualType DestType = CastExpr->getTypeAsWritten().getCanonicalType();
- auto ParenRange = CharSourceRange::getTokenRange(CastExpr->getLParenLoc(),
- CastExpr->getRParenLoc());
if (SourceType == DestType) {
diag(CastExpr->getLocStart(), "Redundant cast to the same type.")
<< FixItHint::CreateRemoval(ParenRange);
@@ -84,8 +88,6 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
auto ReplaceWithCast = [&](StringRef CastType) {
diag_builder << ("Use " + CastType + ".").str();
- if (ParenRange.getBegin().isMacroID() || ParenRange.getEnd().isMacroID())
- return;
const Expr *SubExpr = CastExpr->getSubExprAsWritten()->IgnoreImpCasts();
std::string CastText = (CastType + "<" + DestTypeString + ">").str();
OpenPOWER on IntegriCloud