Skip to content
Snippets Groups Projects
Commit 44f1206f authored by Serge Pavlov's avatar Serge Pavlov
Browse files

Fixed error recovery if sizeof is used without parenthesis

Changes made in r192200 fixed PR16992, which requested fixit suggesting
parenthesis if sizeof is followed by type-id. However expression in form
T() followed by ')' was incorrectly considered as a type-id if 'T' is
typedef name. This change fixes this case.

Differential Revision: http://llvm-reviews.chandlerc.com/D2440


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199284 91177308-0d34-0410-b5e6-96231b3b80d8
parent b13e4cc9
No related branches found
No related tags found
No related merge requests found
...@@ -1788,6 +1788,7 @@ private: ...@@ -1788,6 +1788,7 @@ private:
/// disambiguation will occur. /// disambiguation will occur.
enum TentativeCXXTypeIdContext { enum TentativeCXXTypeIdContext {
TypeIdInParens, TypeIdInParens,
TypeIdUnambiguous,
TypeIdAsTemplateArgument TypeIdAsTemplateArgument
}; };
...@@ -1806,6 +1807,16 @@ private: ...@@ -1806,6 +1807,16 @@ private:
return isTypeIdInParens(isAmbiguous); return isTypeIdInParens(isAmbiguous);
} }
/// \brief Checks if the current tokens form type-id or expression.
/// It is similar to isTypeIdInParens but does not suppose that type-id
/// is in parenthesis.
bool isTypeIdUnambiguously() {
bool IsAmbiguous;
if (getLangOpts().CPlusPlus)
return isCXXTypeId(TypeIdUnambiguous, IsAmbiguous);
return isTypeSpecifierQualifier();
}
/// isCXXDeclarationStatement - C++-specialized function that disambiguates /// isCXXDeclarationStatement - C++-specialized function that disambiguates
/// between a declaration or an expression statement, when parsing function /// between a declaration or an expression statement, when parsing function
/// bodies. Returns true for declaration, false for expression. /// bodies. Returns true for declaration, false for expression.
......
...@@ -1492,8 +1492,7 @@ Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok, ...@@ -1492,8 +1492,7 @@ Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok,
// pathenthesis around type name. // pathenthesis around type name.
if (OpTok.is(tok::kw_sizeof) || OpTok.is(tok::kw___alignof) || if (OpTok.is(tok::kw_sizeof) || OpTok.is(tok::kw___alignof) ||
OpTok.is(tok::kw_alignof) || OpTok.is(tok::kw__Alignof)) { OpTok.is(tok::kw_alignof) || OpTok.is(tok::kw__Alignof)) {
bool isAmbiguousTypeId; if (isTypeIdUnambiguously()) {
if (isTypeIdInParens(isAmbiguousTypeId)) {
DeclSpec DS(AttrFactory); DeclSpec DS(AttrFactory);
ParseSpecifierQualifierList(DS); ParseSpecifierQualifierList(DS);
Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
......
...@@ -118,3 +118,10 @@ void test3() { ...@@ -118,3 +118,10 @@ void test3() {
(void)s1.foo(); (void)s1.foo();
(void)s2.foo(); (void)s2.foo();
} }
namespace pr16992 {
typedef int T;
unsigned getsz() {
return (sizeof T());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment