From 222e2a7620e6520ffaf4fc4e69d79c18da31542e Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Mon, 24 Sep 2012 09:58:17 +1000 Subject: Add the clang library to the repo (with some of my changes, too). --- clang/test/SemaTemplate/temp_explicit.cpp | 151 ++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 clang/test/SemaTemplate/temp_explicit.cpp (limited to 'clang/test/SemaTemplate/temp_explicit.cpp') diff --git a/clang/test/SemaTemplate/temp_explicit.cpp b/clang/test/SemaTemplate/temp_explicit.cpp new file mode 100644 index 0000000..80c90d0 --- /dev/null +++ b/clang/test/SemaTemplate/temp_explicit.cpp @@ -0,0 +1,151 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wc++11-compat %s +// +// Tests explicit instantiation of templates. +template class X0 { }; + +namespace N { + template class X1 { }; +} + +// Check the syntax of explicit instantiations. +template class X0; +template class X0; // expected-note{{previous}} + +template class N::X1; +template class ::N::X1; + +using namespace N; + +// Check for some bogus syntax that probably means that the user +// wanted to write an explicit specialization, but forgot the '<>' +// after 'template'. +template class X0 { }; // expected-error{{explicit specialization}} + +// Check for explicit instantiations that come after other kinds of +// instantiations or declarations. +template class X0; // expected-error{{duplicate}} + +template<> class X0 { }; // expected-note{{previous}} +template class X0; // expected-warning{{ignored}} + +void foo(X0) { } +template class X0; + +// Check that explicit instantiations actually produce definitions. We +// determine whether this happens by placing semantic errors in the +// definition of the template we're instantiating. +template struct X2; // expected-note{{declared here}} + +template struct X2; // expected-error{{undefined template}} + +template +struct X2 { + void f0(T*); // expected-error{{pointer to a reference}} +}; + +template struct X2; // okay +template struct X2; // expected-note{{in instantiation of}} + +// Check that explicit instantiations instantiate member classes. +template struct X3 { + struct Inner { + void f(T*); // expected-error{{pointer to a reference}} + }; +}; + +void f1(X3); // okay, Inner, not instantiated + +template struct X3; // expected-note{{instantiation}} + +template struct X4 { + struct Inner { + struct VeryInner { + void f(T*); // expected-error 2{{pointer to a reference}} + }; + }; +}; + +void f2(X4); // okay, Inner, not instantiated +void f3(X4::Inner); // okay, Inner::VeryInner, not instantiated + +template struct X4; // expected-note{{instantiation}} +template struct X4; // expected-note{{instantiation}} + +// Check explicit instantiation of member classes +namespace N2 { + +template +struct X5 { + struct Inner1 { + void f(T&); + }; + + struct Inner2 { // expected-note {{here}} + struct VeryInner { + void g(T*); // expected-error 2{{pointer to a reference}} + }; + }; +}; + +} + +template struct N2::X5::Inner2; + +using namespace N2; +template struct X5::Inner2; // expected-note{{instantiation}} + +void f4(X5::Inner2); +template struct X5::Inner2; // expected-note{{instantiation}} + +namespace N3 { + template struct N2::X5::Inner2; // expected-warning {{explicit instantiation of 'Inner2' not in a namespace enclosing 'N2'}} +} + +struct X6 { + struct Inner { // expected-note{{here}} + void f(); + }; +}; + +template struct X6::Inner; // expected-error{{non-templated}} + +// PR5559 +template +struct Foo; + +template <> +struct Foo // expected-note{{header not required for explicitly-specialized}} +{ + template + struct Bar + {}; +}; + +template <> // expected-warning{{extraneous template parameter list}} +template <> +struct Foo::Bar +{}; + +namespace N1 { + + template struct X7 { }; // expected-note{{here}} + + namespace Inner { + template struct X8 { }; + } + + template struct X7; + template struct Inner::X8; +} + +template struct X9 { }; // expected-note{{here}} + +template struct ::N1::Inner::X8; + +namespace N2 { + using namespace N1; + + template struct X7; // expected-warning{{must occur in namespace}} + + template struct X9; // expected-warning{{must occur at global scope}} +} -- cgit v1.2.3