[cfe-commits] r135195 - in /cfe/trunk: lib/Parse/ParseDeclCXX.cpp test/CXX/temp/p3.cpp test/CXX/temp/temp.res/temp.local/p3.cpp test/SemaCXX/PR9459.cpp test/SemaTemplate/class-template-decl.cpp

Richard Smith richard-llvm at metafoo.co.uk
Thu Jul 14 14:35:26 PDT 2011


Author: rsmith
Date: Thu Jul 14 16:35:26 2011
New Revision: 135195

URL: http://llvm.org/viewvc/llvm-project?rev=135195&view=rev
Log:
PR10359: Template declarations which define classes are not permitted to also contain declarators. Previously we would accept code like this:

  template<typename T> struct S { } f() { return 0; }

This case now produces a missing ';' diagnostic, since that seems like a much more likely error than an attempt to declare a function or variable in addition to the class template.

Treat this 

Added:
    cfe/trunk/test/CXX/temp/p3.cpp
Modified:
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
    cfe/trunk/test/CXX/temp/temp.res/temp.local/p3.cpp
    cfe/trunk/test/SemaCXX/PR9459.cpp
    cfe/trunk/test/SemaTemplate/class-template-decl.cpp

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=135195&r1=135194&r2=135195&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Thu Jul 14 16:35:26 2011
@@ -1291,6 +1291,11 @@
       break;
     }
 
+    // C++ [temp]p3 In a template-declaration which defines a class, no
+    // declarator is permitted.
+    if (TemplateInfo.Kind)
+      ExpectedSemi = true;
+
     if (ExpectedSemi) {
       ExpectAndConsume(tok::semi, diag::err_expected_semi_after_tagdecl,
                        TagType == DeclSpec::TST_class ? "class"

Added: cfe/trunk/test/CXX/temp/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/p3.cpp?rev=135195&view=auto
==============================================================================
--- cfe/trunk/test/CXX/temp/p3.cpp (added)
+++ cfe/trunk/test/CXX/temp/p3.cpp Thu Jul 14 16:35:26 2011
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify %s
+
+template<typename T> struct S {
+  static int a, b;
+};
+
+template<typename T> int S<T>::a, S<T>::b; // expected-error {{can only declare a single entity}}
+
+// FIXME: the last two diagnostics here are terrible.
+template<typename T> struct A { static A a; } A<T>::a; // expected-error {{expected ';' after struct}} \
+                                                          expected-error {{use of undeclared identifier 'T'}} \
+                                                          expected-error {{cannot name the global scope}} \
+                                                          expected-error {{no member named 'a' in the global namespace}}
+
+template<typename T> struct B { } f(); // expected-error {{expected ';' after struct}} \
+                                          expected-error {{requires a type specifier}}
+
+template<typename T> struct C { } // expected-error {{expected ';' after struct}}
+
+A<int> c;

Modified: cfe/trunk/test/CXX/temp/temp.res/temp.local/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.res/temp.local/p3.cpp?rev=135195&r1=135194&r2=135195&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.res/temp.local/p3.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.res/temp.local/p3.cpp Thu Jul 14 16:35:26 2011
@@ -22,11 +22,11 @@
 namespace PR6717 {
   template <typename T>
   class WebVector {
-  }
+  } // expected-error {{expected ';' after class}}
 
-    WebVector(const WebVector<T>& other) { } 
+    WebVector(const WebVector<T>& other) { } // expected-error{{undeclared identifier 'T'}} \
+                                                expected-error{{requires a type specifier}}
 
   template <typename C>
-  WebVector<T>& operator=(const C& other) { } // expected-error{{unknown type name 'WebVector'}} \
-  // expected-error{{unqualified-id}}
+  WebVector<T>& operator=(const C& other) { } // expected-error{{undeclared identifier 'T'}}
 }

Modified: cfe/trunk/test/SemaCXX/PR9459.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR9459.cpp?rev=135195&r1=135194&r2=135195&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/PR9459.cpp (original)
+++ cfe/trunk/test/SemaCXX/PR9459.cpp Thu Jul 14 16:35:26 2011
@@ -3,5 +3,5 @@
 // Don't crash.
 
 template<typename>struct ae_same;
-template<typename>struct ts{}ap()
+template<typename>struct ts{}ap() // expected-error {{expected ';' after struct}} expected-error {{requires a type specifier}}
 {ts<a>::ap<ae_same<int>::&ae_same<>>::p(a); }; // expected-error {{use of undeclared identifier 'a'}}

Modified: cfe/trunk/test/SemaTemplate/class-template-decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/class-template-decl.cpp?rev=135195&r1=135194&r2=135195&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/class-template-decl.cpp (original)
+++ cfe/trunk/test/SemaTemplate/class-template-decl.cpp Thu Jul 14 16:35:26 2011
@@ -50,7 +50,7 @@
   template<typename T> class X; // expected-error{{expression}}
 }
 
-template<typename T> class X1 { } var; // expected-error{{declared as a template}}
+template<typename T> class X1 var; // expected-error{{declared as a template}}
 
 namespace M {
 }





More information about the cfe-commits mailing list