summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-05-13 18:28:20 +0000
committerDouglas Gregor <dgregor@apple.com>2009-05-13 18:28:20 +0000
commitf61eca93c05f788ac53cd34e02be82761c2e1b9c (patch)
tree25c5ab69c8d8cac2dd70358bca7656055119beeb /clang/test
parent69921959b417f9c64727aaef41147b067bc890d7 (diff)
downloadbcm5719-llvm-f61eca93c05f788ac53cd34e02be82761c2e1b9c.tar.gz
bcm5719-llvm-f61eca93c05f788ac53cd34e02be82761c2e1b9c.zip
Improve the semantic checking for explicit instantiations of
templates. In particular: - An explicit instantiation can follow an implicit instantiation (we were improperly diagnosing this as an error, previously). - In C++0x, an explicit instantiation that follows an explicit specialization of the same template specialization is ignored. In C++98, we just emit an extension warning. - In C++0x, an explicit instantiation must be in a namespace enclosing the original template. C++98 has no such requirement. Also, fixed a longstanding FIXME regarding the integral type that is used for the size of a constant array type when it is being instantiated. llvm-svn: 71689
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/SemaTemplate/temp_explicit.cpp10
-rw-r--r--clang/test/SemaTemplate/temp_explicit_cxx0x.cpp24
2 files changed, 29 insertions, 5 deletions
diff --git a/clang/test/SemaTemplate/temp_explicit.cpp b/clang/test/SemaTemplate/temp_explicit.cpp
index 527532cfa9b..b6009bd9c16 100644
--- a/clang/test/SemaTemplate/temp_explicit.cpp
+++ b/clang/test/SemaTemplate/temp_explicit.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-cc -fsyntax-only -verify %s
+// RUN: clang-cc -fsyntax-only -verify -pedantic %s
//
// Tests explicit instantiation of templates.
template<typename T, typename U = T> class X0 { };
@@ -24,13 +24,13 @@ template class X0<double> { }; // expected-error{{explicit specialization}}
// Check for explicit instantiations that come after other kinds of
// instantiations or declarations.
-template class X0<int, int>; // expected-error{{after}}
+template class X0<int, int>; // expected-error{{duplicate}}
template<> class X0<char> { }; // expected-note{{previous}}
-template class X0<char>; // expected-error{{after}}
+template class X0<char>; // expected-warning{{ignored}}
-void foo(X0<short>) { } // expected-note{{previous}}
-template class X0<short>; // expected-error{{after}}
+void foo(X0<short>) { }
+template class X0<short>;
// Check that explicit instantiations actually produce definitions. We
// determine whether this happens by placing semantic errors in the
diff --git a/clang/test/SemaTemplate/temp_explicit_cxx0x.cpp b/clang/test/SemaTemplate/temp_explicit_cxx0x.cpp
new file mode 100644
index 00000000000..7045afc3032
--- /dev/null
+++ b/clang/test/SemaTemplate/temp_explicit_cxx0x.cpp
@@ -0,0 +1,24 @@
+// RUN: clang-cc -fsyntax-only -std=c++0x -verify %s
+namespace N1 {
+
+ template<typename T> struct X0 { }; // expected-note{{here}}
+
+ namespace Inner {
+ template<typename T> struct X1 { };
+ }
+
+ template struct X0<int>;
+ template struct Inner::X1<int>;
+}
+
+template<typename T> struct X2 { }; // expected-note{{here}}
+
+template struct ::N1::Inner::X1<float>;
+
+namespace N2 {
+ using namespace N1;
+
+ template struct X0<double>; // expected-error{{not in a namespace enclosing}}
+
+ template struct X2<float>; // expected-error{{at global scope}}
+}
OpenPOWER on IntegriCloud