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/class-template-spec.cpp | 121 ++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 clang/test/SemaTemplate/class-template-spec.cpp (limited to 'clang/test/SemaTemplate/class-template-spec.cpp') diff --git a/clang/test/SemaTemplate/class-template-spec.cpp b/clang/test/SemaTemplate/class-template-spec.cpp new file mode 100644 index 0000000..f9015b3 --- /dev/null +++ b/clang/test/SemaTemplate/class-template-spec.cpp @@ -0,0 +1,121 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +template struct A; // expected-note {{template is declared here}} \ + // expected-note{{explicitly specialized}} + +template<> struct A; // expected-note{{forward declaration}} + +template<> struct A { // expected-note{{previous definition}} + int x; +}; + +template<> struct A { // expected-note{{previous definition}} + int y; +}; + +int test_specs(A *a1, A *a2) { + return a1->x + a2->y; +} + +int test_incomplete_specs(A *a1, + A *a2) +{ + (void)a1->x; // expected-error{{member access into incomplete type}} + (void)a2->x; // expected-error{{implicit instantiation of undefined template 'A'}} +} + +typedef float FLOAT; + +template<> struct A; + +template<> struct A { }; // expected-error{{redefinition}} + +template<> struct A { }; // expected-error{{redefinition}} + +template struct X; + +template <> struct X { int foo(); }; // #1 +template <> struct X { int bar(); }; // #2 + +typedef int int_type; +void testme(X *x1, X *x2) { + (void)x1->foo(); // okay: refers to #1 + (void)x2->bar(); // okay: refers to #2 +} + +// Make sure specializations are proper classes. +template<> +struct A { + A(); +}; + +A::A() { } + +// Make sure we can see specializations defined before the primary template. +namespace N{ + template struct A0; +} + +namespace N { + template<> + struct A0 { + typedef void* pointer; + }; +} + +namespace N { + template + struct A0 { + void foo(A0::pointer p = 0); + }; +} + +// Diagnose specialization errors +struct A { }; // expected-error{{template specialization requires 'template<>'}} + +template<> struct ::A; + +namespace N { + template struct B; // expected-note 2{{explicitly specialized}} + + template<> struct ::N::B; // okay + template<> struct ::N::B; // okay + template<> struct ::N::B; // okay + + int f(int); +} + +template<> struct N::B { }; // okay + +template<> struct N::B { }; // expected-warning{{C++11 extension}} + +namespace M { + template<> struct ::N::B { }; // expected-error{{class template specialization of 'B' not in a namespace enclosing 'N'}} + + template<> struct ::A; // expected-error{{originally}} +} + +template<> struct N::B { + int testf(int x) { return f(x); } +}; + +// PR5264 +template class Foo; +Foo* v; +Foo& F() { return *v; } +template class Foo {}; +Foo x; + + +// Template template parameters +template class Wibble> +class Wibble { }; // expected-error{{cannot specialize a template template parameter}} + +namespace rdar9676205 { + template + struct X { + template + struct X { // expected-error{{explicit specialization of 'X' in class scope}} + }; + }; + +} -- cgit v1.2.3