[cfe-commits] r55833 - in /cfe/trunk: lib/Parse/ParseDecl.cpp test/Parser/cxx-typeof.cpp
Argiris Kirtzidis
akyrtzi at gmail.com
Fri Sep 5 04:26:20 PDT 2008
Author: akirtzidis
Date: Fri Sep 5 06:26:19 2008
New Revision: 55833
URL: http://llvm.org/viewvc/llvm-project?rev=55833&view=rev
Log:
Support "typeof unary-expression" (GNU C++ extension).
Added:
cfe/trunk/test/Parser/cxx-typeof.cpp
Modified:
cfe/trunk/lib/Parse/ParseDecl.cpp
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=55833&r1=55832&r2=55833&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Sep 5 06:26:19 2008
@@ -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()) {
Added: cfe/trunk/test/Parser/cxx-typeof.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-typeof.cpp?rev=55833&view=auto
==============================================================================
--- cfe/trunk/test/Parser/cxx-typeof.cpp (added)
+++ cfe/trunk/test/Parser/cxx-typeof.cpp Fri Sep 5 06:26:19 2008
@@ -0,0 +1,7 @@
+// RUN: clang -fsyntax-only -verify %s
+
+static void test() {
+ int *pi;
+ int x;
+ typeof pi[x] y;
+}
More information about the cfe-commits
mailing list