diff options
author | Serge Pavlov <sepavloff@gmail.com> | 2013-10-08 16:56:30 +0000 |
---|---|---|
committer | Serge Pavlov <sepavloff@gmail.com> | 2013-10-08 16:56:30 +0000 |
commit | aa57a64ef69c774a37420c79a8d3b50d559c3661 (patch) | |
tree | 6e7c53074974b57ce2300ddecc0cabdcb4352dc2 /clang/lib/Parse/ParseExpr.cpp | |
parent | 016be42362c6b9caa3fd0cbc218257a82bb43491 (diff) | |
download | bcm5719-llvm-aa57a64ef69c774a37420c79a8d3b50d559c3661.tar.gz bcm5719-llvm-aa57a64ef69c774a37420c79a8d3b50d559c3661.zip |
Add fixits suggesting parenthesis around type name in expressions like sizeof.
This fixes PR16992 - Fixit missing when "sizeof type" found.
llvm-svn: 192200
Diffstat (limited to 'clang/lib/Parse/ParseExpr.cpp')
-rw-r--r-- | clang/lib/Parse/ParseExpr.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index 847b074d5c8..582721cf40f 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -1589,6 +1589,28 @@ Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok, // If the operand doesn't start with an '(', it must be an expression. if (Tok.isNot(tok::l_paren)) { + // If construct allows a form without parenthesis, user may forget to put + // pathenthesis around type name. + if (OpTok.is(tok::kw_sizeof) || OpTok.is(tok::kw___alignof) || + OpTok.is(tok::kw_alignof) || OpTok.is(tok::kw__Alignof)) { + bool isAmbiguousTypeId; + if (isTypeIdInParens(isAmbiguousTypeId)) { + DeclSpec DS(AttrFactory); + ParseSpecifierQualifierList(DS); + Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); + ParseDeclarator(DeclaratorInfo); + + SourceLocation LParenLoc = PP.getLocForEndOfToken(OpTok.getLocation()); + SourceLocation RParenLoc = PP.getLocForEndOfToken(PrevTokLocation); + Diag(LParenLoc, diag::err_missed_parenthesis_around_typename) + << OpTok.getName() + << FixItHint::CreateInsertion(LParenLoc, "(") + << FixItHint::CreateInsertion(RParenLoc, ")"); + isCastExpr = true; + return ExprEmpty(); + } + } + isCastExpr = false; if (OpTok.is(tok::kw_typeof) && !getLangOpts().CPlusPlus) { Diag(Tok,diag::err_expected_lparen_after_id) << OpTok.getIdentifierInfo(); |