// Skip variable declaration.
bool VarDecl = possibleVarDecl(MI, MI->tokens_begin());
+ // Skip the goto argument with an arbitrary number of subsequent stars.
+ bool FoundGoto = false;
+
for (auto TI = MI->tokens_begin(), TE = MI->tokens_end(); TI != TE; ++TI) {
// First token.
if (TI == MI->tokens_begin())
continue;
}
+ // There should not be extra parentheses for the goto argument.
+ if (Tok.is(tok::kw_goto)) {
+ FoundGoto = true;
+ continue;
+ }
+
// Only interested in identifiers.
- if (!Tok.isOneOf(tok::identifier, tok::raw_identifier))
+ if (!Tok.isOneOf(tok::identifier, tok::raw_identifier)) {
+ FoundGoto = false;
continue;
+ }
// Only interested in macro arguments.
if (MI->getParameterNum(Tok.getIdentifierInfo()) < 0)
if (MI->isVariadic())
continue;
- Check->diag(Tok.getLocation(), "macro argument should be enclosed in "
- "parentheses")
- << FixItHint::CreateInsertion(Tok.getLocation(), "(")
- << FixItHint::CreateInsertion(Tok.getLocation().getLocWithOffset(
- PP->getSpelling(Tok).length()),
- ")");
+ if (!FoundGoto) {
+ Check->diag(Tok.getLocation(), "macro argument should be enclosed in "
+ "parentheses")
+ << FixItHint::CreateInsertion(Tok.getLocation(), "(")
+ << FixItHint::CreateInsertion(Tok.getLocation().getLocWithOffset(
+ PP->getSpelling(Tok).length()),
+ ")");
+ }
+
+ FoundGoto = false;
}
}
// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: macro argument should be enclosed in parentheses [bugprone-macro-parentheses]
#define BAD5(X) A*B=(C*)X+2
// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: macro argument should be enclosed in parentheses [bugprone-macro-parentheses]
+#define BAD6(x) goto *x;
+// CHECK-MESSAGES: :[[@LINE-1]]:33: warning: macro argument should be enclosed in parentheses [bugprone-macro-parentheses]
+#define BAD7(x, y) if (x) goto y; else x;
+// CHECK-MESSAGES: :[[@LINE-1]]:47: warning: macro argument should be enclosed in parentheses [bugprone-macro-parentheses]
#define GOOD1 1
#define GOOD2 (1+2)
#define GOOD31(X) A*X=2
#define GOOD32(X) std::vector<X>
#define GOOD33(x) if (!a__##x) a_##x = &f(#x)
+#define GOOD34(x, y) if (x) goto y;
+#define GOOD35(x, y) if (x) goto *(y);
// These are allowed for now..
#define MAYBE1 *12.34