]> granicus.if.org Git - clang/commitdiff
PR10359: Template declarations which define classes are not permitted to also contain...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 14 Jul 2011 21:35:26 +0000 (21:35 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 14 Jul 2011 21:35:26 +0000 (21:35 +0000)
  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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135195 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseDeclCXX.cpp
test/CXX/temp/p3.cpp [new file with mode: 0644]
test/CXX/temp/temp.res/temp.local/p3.cpp
test/SemaCXX/PR9459.cpp
test/SemaTemplate/class-template-decl.cpp

index d78f3728e1beeb61004ef0c521c6b9cc6bb4b372..172049c3405372c88f344ecd168530d03a706ba0 100644 (file)
@@ -1291,6 +1291,11 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
       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"
diff --git a/test/CXX/temp/p3.cpp b/test/CXX/temp/p3.cpp
new file mode 100644 (file)
index 0000000..16ebb38
--- /dev/null
@@ -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;
index 88f8963e6b62c7ab9efc5a6088278197fcc78886..54da8856fe46001cc5d10ad4fbe1845ff0587485 100644 (file)
@@ -22,11 +22,11 @@ template <class T> struct Derived: Base<int>, Base<char> {
 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'}}
 }
index dfb242dc59524305a785f41228a700ff76d81842..2b96f34e8a72a93f053bd92fa76c94e4a31a4bdb 100644 (file)
@@ -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'}}
index e7722123f9c22feace219465f4688f2db28bf69a..2e84e93ead97376fdd5c4f919766154f01f05fdc 100644 (file)
@@ -50,7 +50,7 @@ void f() {
   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 {
 }