[cfe-commits] r40656 - in /cfe/trunk: Parse/ParseDecl.cpp test/Parser/typeof.c

Steve Naroff snaroff at apple.com
Tue Jul 31 16:56:32 PDT 2007


Author: snaroff
Date: Tue Jul 31 18:56:32 2007
New Revision: 40656

URL: http://llvm.org/viewvc/llvm-project?rev=40656&view=rev
Log:

Tighten up Parser::ParseTypeofSpecifier().
Add some more tests to typeof.c. Also added a couple of missing "expect" attributes that caused the test to fail.


Modified:
    cfe/trunk/Parse/ParseDecl.cpp
    cfe/trunk/test/Parser/typeof.c

Modified: cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseDecl.cpp?rev=40656&r1=40655&r2=40656&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/Parse/ParseDecl.cpp Tue Jul 31 18:56:32 2007
@@ -354,7 +354,7 @@
 /// [GNU]   '_Decimal32'
 /// [GNU]   '_Decimal64'
 /// [GNU]   '_Decimal128'
-/// [GNU]   typeof-specifier                      [TODO]
+/// [GNU]   typeof-specifier
 /// [OBJC]  class-name objc-protocol-refs[opt]    [TODO]
 /// [OBJC]  typedef-name objc-protocol-refs       [TODO]
 /// [OBJC]  objc-protocol-refs                    [TODO]
@@ -1424,24 +1424,30 @@
   if (isTypeSpecifierQualifier()) {
     TypeTy *Ty = ParseTypeName();
 
-    const char *PrevSpec = 0;
-    bool isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typeofType, StartLoc, 
-                                        PrevSpec, Ty);
-    // FIXME: what we have an invalid type? (or Ty is null)
+    assert(Ty && "Parser::ParseTypeofSpecifier(): missing type");
+
+    // Match the ')'.
+    if (Tok.getKind() == tok::r_paren) {
+      RParenLoc = ConsumeParen();
+      const char *PrevSpec = 0;
+      if (DS.SetTypeSpecType(DeclSpec::TST_typeofType, StartLoc, PrevSpec, Ty))
+        // Duplicate type specifiers (e.g. "int typeof(int)).
+        Diag(StartLoc, diag::err_invalid_decl_spec_combination, PrevSpec);
+    } else // error
+      MatchRHSPunctuation(tok::r_paren, LParenLoc);
   } else { // we have an expression.
     ExprResult Result = ParseExpression();
-    if (Result.isInvalid) {
-      SkipUntil(tok::r_paren);
-    }
-    const char *PrevSpec = 0;
-    bool isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typeofExpr, StartLoc, 
-                                        PrevSpec, Result.Val);
-    // FIXME: what we have an invalid type? (or Result.Val is null)
+    
+    // Match the ')'.
+    if (!Result.isInvalid && Tok.getKind() == tok::r_paren) {
+      RParenLoc = ConsumeParen();
+      const char *PrevSpec = 0;
+      if (DS.SetTypeSpecType(DeclSpec::TST_typeofExpr, StartLoc, PrevSpec, 
+                             Result.Val))
+        // Duplicate type specifiers (e.g. "int typeof(int)).
+        Diag(StartLoc, diag::err_invalid_decl_spec_combination, PrevSpec);
+    } else // error
+      MatchRHSPunctuation(tok::r_paren, LParenLoc);
   }
-  // Match the ')'.
-  if (Tok.getKind() == tok::r_paren)
-    RParenLoc = ConsumeParen();
-  else
-    MatchRHSPunctuation(tok::r_paren, LParenLoc);
 }
 

Modified: cfe/trunk/test/Parser/typeof.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/typeof.c?rev=40656&r1=40655&r2=40656&view=diff

==============================================================================
--- cfe/trunk/test/Parser/typeof.c (original)
+++ cfe/trunk/test/Parser/typeof.c Tue Jul 31 18:56:32 2007
@@ -5,11 +5,16 @@
 static void test() {
   int *pi;
 
+  int typeof (int) aIntInt; // expected-error{{cannot combine with previous 'int' declaration specifier}} expected-warning{{extension used}}
+  short typeof (int) aShortInt; // expected-error{{'short typeof' is invalid}} expected-warning{{extension used}}
+  int int ttt; // expected-error{{cannot combine with previous 'int' declaration specifier}}
   typeof(TInt) anInt; // expected-warning{{extension used}}
+  short TInt eee; // expected-error{{parse error}}
+  void ary[7] fff; // expected-error{{array has incomplete element type 'void'}} expected-error{{parse error}}
+  typeof(void ary[7]) anIntError; // expected-warning{{extension used}} expected-error{{expected ')'}} expected-error{{to match this '('}}
   typeof(const int) aci; // expected-warning{{extension used}}
   const typeof (*pi) aConstInt; // expected-warning{{extension used}}
   int xx;
-  short typeof (*pi) aShortInt; // expected-error{{'short typeof' is invalid}}
   int *i;
   i = aci; // expected-warning{{incompatible types assigning 'typeof(int const)' to 'int *'}}
   i = anInt; // expected-warning{{incompatible types assigning 'typeof(TInt)' to 'int *'}}





More information about the cfe-commits mailing list