Support "typeof unary-expression" (GNU C++ extension).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55833 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index cd2dda2..2a8ab3f 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -1556,9 +1556,10 @@
NumElements.Val, StartLoc));
}
-/// [GNU] typeof-specifier:
-/// typeof ( expressions )
-/// typeof ( type-name )
+/// [GNU] typeof-specifier:
+/// typeof ( expressions )
+/// typeof ( type-name )
+/// [GNU/C++] typeof unary-expression
///
void Parser::ParseTypeofSpecifier(DeclSpec &DS) {
assert(Tok.is(tok::kw_typeof) && "Not a typeof specifier");
@@ -1566,9 +1567,26 @@
SourceLocation StartLoc = ConsumeToken();
if (Tok.isNot(tok::l_paren)) {
- Diag(Tok, diag::err_expected_lparen_after, BuiltinII->getName());
+ if (!getLang().CPlusPlus) {
+ Diag(Tok, diag::err_expected_lparen_after, BuiltinII->getName());
+ return;
+ }
+
+ ExprResult Result = ParseCastExpression(true/*isUnaryExpression*/);
+ if (Result.isInvalid)
+ return;
+
+ const char *PrevSpec = 0;
+ // Check for duplicate type specifiers.
+ if (DS.SetTypeSpecType(DeclSpec::TST_typeofExpr, StartLoc, PrevSpec,
+ Result.Val))
+ Diag(StartLoc, diag::err_invalid_decl_spec_combination, PrevSpec);
+
+ // FIXME: Not accurate, the range gets one token more than it should.
+ DS.SetRangeEnd(Tok.getLocation());
return;
}
+
SourceLocation LParenLoc = ConsumeParen(), RParenLoc;
if (isTypeSpecifierQualifier()) {