[cfe-commits] r83553 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp test/CXX/temp/temp.spec/temp.expl.spec/p5.cpp

Douglas Gregor dgregor at apple.com
Thu Oct 8 09:41:23 PDT 2009


Author: dgregor
Date: Thu Oct  8 11:41:22 2009
New Revision: 83553

URL: http://llvm.org/viewvc/llvm-project?rev=83553&view=rev
Log:
Add more testing for the properties of explicit specialization. 

Also, eliminate a redundant diagnostic by marking a variable declared
with incomplete type as an invalid declaration.


Added:
    cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp   (with props)
    cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp   (with props)
    cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p5.cpp   (with props)
Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=83553&r1=83552&r2=83553&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Oct  8 11:41:22 2009
@@ -3454,6 +3454,8 @@
             
             FinalizeVarWithDestructor(Var, InitType);
           }
+        } else {
+          Var->setInvalidDecl();
         }
       }
     }

Added: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp?rev=83553&view=auto

==============================================================================
--- cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp (added)
+++ cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp Thu Oct  8 11:41:22 2009
@@ -0,0 +1,14 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+namespace N {
+  template<class T> class X;
+}
+
+// FIXME: this diagnostic is terrible (PR3844).
+template<> class X<int> { /* ... */ };	// expected-error {{unqualified-id}}
+
+namespace N {
+  
+template<> class X<char*> { /* ... */ };	// OK: X is a template
+  
+}
\ No newline at end of file

Propchange: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp

------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp

------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp

------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp?rev=83553&view=auto

==============================================================================
--- cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp (added)
+++ cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp Thu Oct  8 11:41:22 2009
@@ -0,0 +1,59 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+struct IntHolder { // expected-note{{here}}
+  IntHolder(int);
+};
+
+template<typename T, typename U>
+struct X { // expected-note{{here}}
+  void f() { 
+    T t; // expected-error{{no matching}}
+  }
+
+  void g() { }
+  
+  struct Inner { 
+    T value; 
+  };
+  
+  static T value;
+};
+
+template<typename T, typename U>
+T X<T, U>::value; // expected-error{{no matching constructor}}
+
+IntHolder &test_X_IntHolderInt(X<IntHolder, int> xih) {
+  xih.g(); // okay
+  xih.f(); // expected-note{{instantiation}}
+  
+  // FIXME: diagnostic here has incorrect reason (PR5154)
+  X<IntHolder, int>::Inner inner; // expected-error{{implicit default}}
+  
+  return X<IntHolder, int>::value; // expected-note{{instantiation}}
+}
+
+// Explicitly specialize the members of X<IntHolder, long> to not cause
+// problems with instantiation.
+template<>
+void X<IntHolder, long>::f() { }
+
+template<>
+struct X<IntHolder, long>::Inner {
+  Inner() : value(17) { }
+  IntHolder value;
+};
+
+template<>
+IntHolder X<IntHolder, long>::value = 17;
+
+IntHolder &test_X_IntHolderInt(X<IntHolder, long> xih) {
+  xih.g(); // okay
+  xih.f(); // okay, uses specialization
+  
+  X<IntHolder, long>::Inner inner; // okay, uses specialization
+  
+  return X<IntHolder, long>::value; // okay, uses specialization
+}
+
+template<>
+X<IntHolder, long>::X() { } // expected-error{{instantiated member}}

Propchange: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp

------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp

------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp

------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p5.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p5.cpp?rev=83553&view=auto

==============================================================================
--- cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p5.cpp (added)
+++ cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p5.cpp Thu Oct  8 11:41:22 2009
@@ -0,0 +1,61 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+struct IntHolder {
+  IntHolder(int);
+};
+
+template<typename T, typename U>
+struct X {
+  void f() { 
+    T t;
+  }
+  
+  void g() { }
+  
+  struct Inner { 
+    T value; 
+  };
+  
+  static T value;
+};
+
+template<typename T, typename U>
+T X<T, U>::value;
+
+// Explicitly specialize the members of X<IntHolder, long> to not cause
+// problems with instantiation, but only provide declarations (not definitions).
+template<>
+void X<IntHolder, long>::f();
+
+template<>
+struct X<IntHolder, long>::Inner; // expected-note{{forward declaration}}
+
+template<>
+IntHolder X<IntHolder, long>::value;
+
+IntHolder &test_X_IntHolderInt(X<IntHolder, long> xih) {
+  xih.g(); // okay
+  xih.f(); // okay, uses specialization
+  
+  X<IntHolder, long>::Inner inner; // expected-error {{incomplete}}
+  
+  return X<IntHolder, long>::value; // okay, uses specialization
+}
+
+
+template<class T> struct A {
+  void f(T) { /* ... */ }
+};
+
+template<> struct A<int> { 
+  void f(int);
+};
+
+void h() {
+  A<int> a; 
+  a.f(16); // A<int>::f must be defined somewhere
+}
+
+// explicit specialization syntax not used for a member of 
+// explicitly specialized class template specialization 
+void A<int>::f(int) { /* ... */ }

Propchange: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p5.cpp

------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p5.cpp

------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p5.cpp

------------------------------------------------------------------------------
    svn:mime-type = text/plain





More information about the cfe-commits mailing list