summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compilerplugins/clang/blockblock.cxx45
-rw-r--r--compilerplugins/clang/test/blockblock.cxx8
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;