[cfe-commits] r156508 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseDecl.cpp test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p2-0x.cpp test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp test/Parser/cxx-throw.cpp test/Parser/cxx11-type-specifier.cpp

Richard Smith richard-llvm at metafoo.co.uk
Wed May 9 13:55:26 PDT 2012


Author: rsmith
Date: Wed May  9 15:55:26 2012
New Revision: 156508

URL: http://llvm.org/viewvc/llvm-project?rev=156508&view=rev
Log:
Push the knowledge that we are parsing a type-id/type-name further into the
parser, and use it to emit better diagnostics in cases where an identifer
can't be looked up as a type name.

Modified:
    cfe/trunk/include/clang/Parse/Parser.h
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p2-0x.cpp
    cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp
    cfe/trunk/test/Parser/cxx-throw.cpp
    cfe/trunk/test/Parser/cxx11-type-specifier.cpp

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=156508&r1=156507&r2=156508&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Wed May  9 15:55:26 2012
@@ -1531,7 +1531,7 @@
   enum DeclSpecContext {
     DSC_normal, // normal context
     DSC_class,  // class context, enables 'friend'
-    DSC_type_specifier, // C++ type-specifier-seq
+    DSC_type_specifier, // C++ type-specifier-seq or C specifier-qualifier-list
     DSC_trailing, // C++11 trailing-type-specifier in a trailing return type
     DSC_top_level // top-level/namespace declaration context
   };

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=156508&r1=156507&r2=156508&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed May  9 15:55:26 2012
@@ -38,6 +38,8 @@
                                  AccessSpecifier AS,
                                  Decl **OwnedType) {
   DeclSpecContext DSC = getDeclSpecContextFromDeclaratorContext(Context);
+  if (DSC == DSC_normal)
+    DSC = DSC_type_specifier;
 
   // Parse the common declaration-specifiers piece.
   DeclSpec DS(AttrFactory);
@@ -1543,7 +1545,8 @@
 
   // Validate declspec for type-name.
   unsigned Specs = DS.getParsedSpecifiers();
-  if (DSC == DSC_type_specifier && !DS.hasTypeSpecifier()) {
+  if ((DSC == DSC_type_specifier || DSC == DSC_trailing) &&
+      !DS.hasTypeSpecifier()) {
     Diag(Tok, diag::err_expected_type);
     DS.SetTypeSpecError();
   } else if (Specs == DeclSpec::PQ_None && !DS.getNumProtocolQualifiers() &&
@@ -1640,7 +1643,7 @@
   // FIXME: Don't bail out here in languages with no implicit int (like
   // C++ with no -fms-extensions). This is much more likely to be an undeclared
   // type or typo than a use of implicit int.
-  if (DSC != DSC_type_specifier &&
+  if (DSC != DSC_type_specifier && DSC != DSC_trailing &&
       isValidAfterIdentifierInDeclarator(NextToken())) {
     // If this token is valid for implicit int, e.g. "static x = 4", then
     // we just avoid eating the identifier, so it will be parsed as the

Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p2-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p2-0x.cpp?rev=156508&r1=156507&r2=156508&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p2-0x.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p2-0x.cpp Wed May  9 15:55:26 2012
@@ -124,9 +124,7 @@
 }
 
 namespace CWG1044 {
-  // FIXME: this diagnostic isn't ideal. one diagnostic is enough.
-  using T = T; // expected-error {{type name requires a specifier}} \
-                  expected-error {{expected ';' after alias declaration}}
+  using T = T; // expected-error {{unknown type name 'T'}}
 }
 
 namespace StdExample {

Modified: cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp?rev=156508&r1=156507&r2=156508&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp (original)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp Wed May  9 15:55:26 2012
@@ -1,3 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
 
-auto j() -> enum { e3 }; // expected-error{{unnamed enumeration must be a definition}} expected-error {{requires a specifier or qualifier}} expected-error {{without trailing return type}}
+// FIXME: We should catch the case of tag with an incomplete type here (which
+// will necessarily be ill-formed as a trailing return type for a function
+// definition), and recover with a "type cannot be defined in a trailing return
+// type" error.
+auto j() -> enum { e3 }; // expected-error{{unnamed enumeration must be a definition}} expected-error {{expected a type}} expected-error {{without trailing return type}}

Modified: cfe/trunk/test/Parser/cxx-throw.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-throw.cpp?rev=156508&r1=156507&r2=156508&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx-throw.cpp (original)
+++ cfe/trunk/test/Parser/cxx-throw.cpp Wed May  9 15:55:26 2012
@@ -13,3 +13,5 @@
   __extension__ throw 1;    // expected-error {{expected expression}}
   (void)throw;              // expected-error {{expected expression}}
 }
+
+void f() throw(static); // expected-error {{expected a type}} expected-error {{does not allow storage class}}

Modified: cfe/trunk/test/Parser/cxx11-type-specifier.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx11-type-specifier.cpp?rev=156508&r1=156507&r2=156508&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx11-type-specifier.cpp (original)
+++ cfe/trunk/test/Parser/cxx11-type-specifier.cpp Wed May  9 15:55:26 2012
@@ -18,3 +18,10 @@
   (void) new struct S {}; // expected-error{{'S' can not be defined in a type specifier}}
   (void) new enum E { e }; // expected-error{{'E' can not be defined in a type specifier}}
 }
+
+// And for trailing-type-specifier-seq
+
+// FIXME: Don't treat an ill-formed trailing-return-type the same as no
+//        trailing-return-type, and avoid the second diagnostic.
+auto f() -> unknown; // expected-error{{unknown type name 'unknown'}} \
+                        expected-error{{'auto' return without trailing return type}}





More information about the cfe-commits mailing list