diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 9d0d1b605903f1896192e749aa9950904be6ebec..aa7aca30af1d0627cfa0c5381cdc2efbdce6d39c 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -1788,6 +1788,7 @@ private: /// disambiguation will occur. enum TentativeCXXTypeIdContext { TypeIdInParens, + TypeIdUnambiguous, TypeIdAsTemplateArgument }; @@ -1806,6 +1807,16 @@ private: 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 /// between a declaration or an expression statement, when parsing function /// bodies. Returns true for declaration, false for expression. diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index d94155ba6c6e2bf11c7cc7fd6de1e5e5e3e15297..f7b0afe60d8866f7b5e5adfbfc0b3d078542e08f 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -1492,8 +1492,7 @@ Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok, // 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)) { + if (isTypeIdUnambiguously()) { DeclSpec DS(AttrFactory); ParseSpecifierQualifierList(DS); Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); diff --git a/test/SemaCXX/expressions.cpp b/test/SemaCXX/expressions.cpp index 2635fb8d176a87199bc630720216cf3df58c23a8..25a9c841725c1c513dab64b24e1164fc214aafa7 100644 --- a/test/SemaCXX/expressions.cpp +++ b/test/SemaCXX/expressions.cpp @@ -118,3 +118,10 @@ void test3() { (void)s1.foo(); (void)s2.foo(); } + +namespace pr16992 { + typedef int T; + unsigned getsz() { + return (sizeof T()); + } +}