diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -2278,12 +2278,20 @@ Declarator DeclaratorInfo(DS, DeclaratorContext::TypeNameContext); ParseDeclarator(DeclaratorInfo); - SourceLocation LParenLoc = PP.getLocForEndOfToken(OpTok.getLocation()); - SourceLocation RParenLoc = PP.getLocForEndOfToken(PrevTokLocation); - Diag(LParenLoc, diag::err_expected_parentheses_around_typename) - << OpTok.getName() - << FixItHint::CreateInsertion(LParenLoc, "(") - << FixItHint::CreateInsertion(RParenLoc, ")"); + SourceLocation OpTokLoc = OpTok.getLocation(); + if (OpTokLoc.isMacroID()) { + SourceLocation OpTokExpansionLoc = + PP.getSourceManager().getFileLoc(OpTokLoc); + Diag(OpTokExpansionLoc, + diag::err_expected_parentheses_around_typename) + << OpTok.getName(); + } else { + SourceLocation LParenLoc = PP.getLocForEndOfToken(OpTokLoc); + SourceLocation RParenLoc = PP.getLocForEndOfToken(PrevTokLocation); + Diag(LParenLoc, diag::err_expected_parentheses_around_typename) + << OpTok.getName() << FixItHint::CreateInsertion(LParenLoc, "(") + << FixItHint::CreateInsertion(RParenLoc, ")"); + } isCastExpr = true; return ExprEmpty(); } diff --git a/clang/test/Parser/sizeof-missing-parens.c b/clang/test/Parser/sizeof-missing-parens.c new file mode 100644 --- /dev/null +++ b/clang/test/Parser/sizeof-missing-parens.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +void Foo(int); + +#define Bar(x) Foo(x) + +void Baz() +{ + Foo(sizeof int); // expected-error {{expected parentheses around type name in sizeof expression}} + Bar(sizeof int); // expected-error {{expected parentheses around type name in sizeof expression}} +}