diff options
author | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-10-15 17:10:06 +1100 |
---|---|---|
committer | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-10-15 17:10:06 +1100 |
commit | be1de4be954c80875ad4108e0a33e8e131b2f2c0 (patch) | |
tree | 1fbbecf276bf7c7bdcbb4dd446099d6d90eaa516 /clang/test/SemaTemplate/class-template-spec.cpp | |
parent | c4626a62754862d20b41e8a46a3574264ea80e6d (diff) | |
parent | f1bd2e48c5324d3f7cda4090c87f8a5b6f463ce2 (diff) |
Merge branch 'master' of ssh://bitbucket.org/czan/honours
Diffstat (limited to 'clang/test/SemaTemplate/class-template-spec.cpp')
-rw-r--r-- | clang/test/SemaTemplate/class-template-spec.cpp | 121 |
1 files changed, 121 insertions, 0 deletions
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<typename T, typename U = int> struct A; // expected-note {{template is declared here}} \ + // expected-note{{explicitly specialized}} + +template<> struct A<double, double>; // expected-note{{forward declaration}} + +template<> struct A<float, float> { // expected-note{{previous definition}} + int x; +}; + +template<> struct A<float> { // expected-note{{previous definition}} + int y; +}; + +int test_specs(A<float, float> *a1, A<float, int> *a2) { + return a1->x + a2->y; +} + +int test_incomplete_specs(A<double, double> *a1, + A<double> *a2) +{ + (void)a1->x; // expected-error{{member access into incomplete type}} + (void)a2->x; // expected-error{{implicit instantiation of undefined template 'A<double, int>'}} +} + +typedef float FLOAT; + +template<> struct A<float, FLOAT>; + +template<> struct A<FLOAT, float> { }; // expected-error{{redefinition}} + +template<> struct A<float, int> { }; // expected-error{{redefinition}} + +template<typename T, typename U = int> struct X; + +template <> struct X<int, int> { int foo(); }; // #1 +template <> struct X<float> { int bar(); }; // #2 + +typedef int int_type; +void testme(X<int_type> *x1, X<float, int> *x2) { + (void)x1->foo(); // okay: refers to #1 + (void)x2->bar(); // okay: refers to #2 +} + +// Make sure specializations are proper classes. +template<> +struct A<char> { + A(); +}; + +A<char>::A() { } + +// Make sure we can see specializations defined before the primary template. +namespace N{ + template<typename T> struct A0; +} + +namespace N { + template<> + struct A0<void> { + typedef void* pointer; + }; +} + +namespace N { + template<typename T> + struct A0 { + void foo(A0<void>::pointer p = 0); + }; +} + +// Diagnose specialization errors +struct A<double> { }; // expected-error{{template specialization requires 'template<>'}} + +template<> struct ::A<double>; + +namespace N { + template<typename T> struct B; // expected-note 2{{explicitly specialized}} + + template<> struct ::N::B<char>; // okay + template<> struct ::N::B<short>; // okay + template<> struct ::N::B<int>; // okay + + int f(int); +} + +template<> struct N::B<int> { }; // okay + +template<> struct N::B<float> { }; // expected-warning{{C++11 extension}} + +namespace M { + template<> struct ::N::B<short> { }; // expected-error{{class template specialization of 'B' not in a namespace enclosing 'N'}} + + template<> struct ::A<long double>; // expected-error{{originally}} +} + +template<> struct N::B<char> { + int testf(int x) { return f(x); } +}; + +// PR5264 +template <typename T> class Foo; +Foo<int>* v; +Foo<int>& F() { return *v; } +template <typename T> class Foo {}; +Foo<int> x; + + +// Template template parameters +template<template<class T> class Wibble> +class Wibble<int> { }; // expected-error{{cannot specialize a template template parameter}} + +namespace rdar9676205 { + template<typename T> + struct X { + template<typename U> + struct X<U*> { // expected-error{{explicit specialization of 'X' in class scope}} + }; + }; + +} |