Kaydet (Commit) 1084e8be authored tarafından Stephan Bergmann's avatar Stephan Bergmann

More targeted check for preprocessing conditionals in loplugin:blockblock

Change-Id: Ib9b6b266ed4bf4d2672aed723c7f92f58c9007b3
üst f4514f35
...@@ -35,48 +35,6 @@ public: ...@@ -35,48 +35,6 @@ public:
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); 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 * ); bool VisitCompoundStmt(CompoundStmt const * );
}; };
...@@ -93,6 +51,9 @@ bool BlockBlock::VisitCompoundStmt(CompoundStmt const * compound) ...@@ -93,6 +51,9 @@ bool BlockBlock::VisitCompoundStmt(CompoundStmt const * compound)
return true; return true;
if (compiler.getSourceManager().isMacroBodyExpansion(inner->getLocStart())) if (compiler.getSourceManager().isMacroBodyExpansion(inner->getLocStart()))
return true; return true;
if (containsPreprocessingConditionalInclusion(compound->getSourceRange())) {
return true;
}
report( report(
DiagnosticsEngine::Warning, DiagnosticsEngine::Warning,
"block directly inside block", "block directly inside block",
......
...@@ -8,12 +8,14 @@ ...@@ -8,12 +8,14 @@
*/ */
int f(bool b1, bool b2) { int f(bool b1, bool b2) {
if (b1 || b2) { if (b1 || b2) { // no warning
#if 0 #if 0
if (b1) if (b1)
#endif #endif
{ { // expected-error {{block directly inside block [loplugin:blockblock]}}
return 0; { // expected-note {{inner block here [loplugin:blockblock]}}
return 0;
}
} }
} }
return 1; return 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment