diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2017-10-04 12:03:23 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2017-10-04 12:03:23 +0200 |
commit | 1084e8be44661aaeacb8801707701013eb3fcdbc (patch) | |
tree | 71e4499ec34de9552518080162622f4bc68e4c9a /compilerplugins/clang | |
parent | f4514f356a08a4108c5cdfb1d12855df297097a4 (diff) |
More targeted check for preprocessing conditionals in loplugin:blockblock
Change-Id: Ib9b6b266ed4bf4d2672aed723c7f92f58c9007b3
Diffstat (limited to 'compilerplugins/clang')
-rw-r--r-- | compilerplugins/clang/blockblock.cxx | 45 | ||||
-rw-r--r-- | compilerplugins/clang/test/blockblock.cxx | 8 |
2 files changed, 8 insertions, 45 deletions
diff --git a/compilerplugins/clang/blockblock.cxx b/compilerplugins/clang/blockblock.cxx index a4ac7ffb8edb..7d274059fedf 100644 --- a/compilerplugins/clang/blockblock.cxx +++ b/compilerplugins/clang/blockblock.cxx @@ -35,48 +35,6 @@ public: TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } - bool TraverseFunctionDecl(FunctionDecl * decl) { - if (containsPreprocessingConditionalInclusion(decl->getSourceRange())) { - return true; - } - return RecursiveASTVisitor::TraverseFunctionDecl(decl); - } - - bool TraverseCXXMethodDecl(CXXMethodDecl * decl) { - if (containsPreprocessingConditionalInclusion(decl->getSourceRange())) { - return true; - } - return RecursiveASTVisitor::TraverseCXXMethodDecl(decl); - } - - bool TraverseCXXConstructorDecl(CXXConstructorDecl * decl) { - if (containsPreprocessingConditionalInclusion(decl->getSourceRange())) { - return true; - } - return RecursiveASTVisitor::TraverseCXXConstructorDecl(decl); - } - - bool TraverseCXXDestructorDecl(CXXDestructorDecl * decl) { - if (containsPreprocessingConditionalInclusion(decl->getSourceRange())) { - return true; - } - return RecursiveASTVisitor::TraverseCXXDestructorDecl(decl); - } - - bool TraverseCXXConversionDecl(CXXConversionDecl * decl) { - if (containsPreprocessingConditionalInclusion(decl->getSourceRange())) { - return true; - } - return RecursiveASTVisitor::TraverseCXXConversionDecl(decl); - } - - bool TraverseObjCMethodDecl(ObjCMethodDecl * decl) { - if (containsPreprocessingConditionalInclusion(decl->getSourceRange())) { - return true; - } - return RecursiveASTVisitor::TraverseObjCMethodDecl(decl); - } - bool VisitCompoundStmt(CompoundStmt const * ); }; @@ -93,6 +51,9 @@ bool BlockBlock::VisitCompoundStmt(CompoundStmt const * compound) return true; if (compiler.getSourceManager().isMacroBodyExpansion(inner->getLocStart())) return true; + if (containsPreprocessingConditionalInclusion(compound->getSourceRange())) { + return true; + } report( DiagnosticsEngine::Warning, "block directly inside block", diff --git a/compilerplugins/clang/test/blockblock.cxx b/compilerplugins/clang/test/blockblock.cxx index 2463ccaa7fd5..bd48ed7d38fa 100644 --- a/compilerplugins/clang/test/blockblock.cxx +++ b/compilerplugins/clang/test/blockblock.cxx @@ -8,12 +8,14 @@ */ int f(bool b1, bool b2) { - if (b1 || b2) { + if (b1 || b2) { // no warning #if 0 if (b1) #endif - { - return 0; + { // expected-error {{block directly inside block [loplugin:blockblock]}} + { // expected-note {{inner block here [loplugin:blockblock]}} + return 0; + } } } return 1; |