forked from OSchip/llvm-project
[clang-tidy] Fix false positives in the macro parentheses checker
Summary: There were false positives in C++ code where macro argument was a type. Reviewers: alexfh Differential Revision: http://reviews.llvm.org/D10801 llvm-svn: 240938
This commit is contained in:
parent
4002ce4834
commit
4a38b0b493
|
@ -151,6 +151,10 @@ void MacroParenthesesPPCallbacks::argument(const Token &MacroNameTok,
|
|||
if (Prev.isOneOf(tok::period, tok::arrow, tok::coloncolon))
|
||||
continue;
|
||||
|
||||
// Argument is a namespace or class.
|
||||
if (Next.is(tok::coloncolon))
|
||||
continue;
|
||||
|
||||
// String concatenation.
|
||||
if (isStringLiteral(Prev.getKind()) || isStringLiteral(Next.getKind()))
|
||||
continue;
|
||||
|
@ -173,6 +177,11 @@ void MacroParenthesesPPCallbacks::argument(const Token &MacroNameTok,
|
|||
if (Prev.isOneOf(tok::equal, tok::kw_return) && Next.is(tok::semi))
|
||||
continue;
|
||||
|
||||
// C++ template parameters.
|
||||
if (PP->getLangOpts().CPlusPlus && Prev.isOneOf(tok::comma, tok::less) &&
|
||||
Next.isOneOf(tok::comma, tok::greater))
|
||||
continue;
|
||||
|
||||
Check->diag(Tok.getLocation(), "macro argument should be enclosed in "
|
||||
"parentheses")
|
||||
<< FixItHint::CreateInsertion(Tok.getLocation(), "(")
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
#define GOOD20 void*
|
||||
#define GOOD21(a) case Fred::a:
|
||||
#define GOOD22(a) if (verbose) return a;
|
||||
#define GOOD23(type) (type::Field)
|
||||
#define GOOD24(t) std::set<t> s
|
||||
#define GOOD25(t) std::set<t,t,t> s
|
||||
|
||||
// These are allowed for now..
|
||||
#define MAYBE1 *12.34
|
||||
|
|
Loading…
Reference in New Issue