blob: c826268c864c4ef76db7e969f49d766814467678 [file] [log] [blame]
Richard Smithbc2e9712014-10-17 20:56:14 +00001// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
Douglas Gregor6bc50582009-05-07 06:41:52 +00002
Douglas Gregor938439b2009-05-07 15:40:54 +00003// This test concerns the identity of dependent types within the
4// canonical type system. This corresponds to C++ [temp.type], which
5// specifies type equivalence within a template.
6//
7// FIXME: template template parameters
Douglas Gregor938439b2009-05-07 15:40:54 +00008
Douglas Gregor6d7a30c2009-05-07 15:31:47 +00009namespace N {
10 template<typename T>
11 struct X2 {
12 template<typename U>
13 struct apply {
14 typedef U* type;
15 };
16 };
17}
18
19namespace Nalias = N;
20
Douglas Gregor6bc50582009-05-07 06:41:52 +000021template<typename T>
22struct X0 { };
23
Douglas Gregor6d7a30c2009-05-07 15:31:47 +000024using namespace N;
25
Douglas Gregor6bc50582009-05-07 06:41:52 +000026template<typename T, typename U>
27struct X1 {
28 typedef T type;
Douglas Gregorae1e53c2009-05-07 06:49:52 +000029 typedef U U_type;
Douglas Gregor6bc50582009-05-07 06:41:52 +000030
31 void f0(T); // expected-note{{previous}}
32 void f0(U);
33 void f0(type); // expected-error{{redeclar}}
34
35 void f1(T*); // expected-note{{previous}}
36 void f1(U*);
37 void f1(type*); // expected-error{{redeclar}}
38
39 void f2(X0<T>*); // expected-note{{previous}}
40 void f2(X0<U>*);
41 void f2(X0<type>*); // expected-error{{redeclar}}
42
43 void f3(X0<T>*); // expected-note{{previous}}
44 void f3(X0<U>*);
45 void f3(::X0<type>*); // expected-error{{redeclar}}
46
Douglas Gregorae1e53c2009-05-07 06:49:52 +000047 void f4(typename T::template apply<U>*); // expected-note{{previous}}
Douglas Gregor6bc50582009-05-07 06:41:52 +000048 void f4(typename U::template apply<U>*);
49 void f4(typename type::template apply<T>*);
Douglas Gregorae1e53c2009-05-07 06:49:52 +000050 void f4(typename type::template apply<U_type>*); // expected-error{{redeclar}}
Douglas Gregor6bc50582009-05-07 06:41:52 +000051
Douglas Gregorae1e53c2009-05-07 06:49:52 +000052 void f5(typename T::template apply<U>::type*); // expected-note{{previous}}
Douglas Gregor6bc50582009-05-07 06:41:52 +000053 void f5(typename U::template apply<U>::type*);
54 void f5(typename U::template apply<T>::type*);
55 void f5(typename type::template apply<T>::type*);
Douglas Gregorae1e53c2009-05-07 06:49:52 +000056 void f5(typename type::template apply<U_type>::type*); // expected-error{{redeclar}}
Douglas Gregor6d7a30c2009-05-07 15:31:47 +000057
58 void f6(typename N::X2<T>::template apply<U> *); // expected-note{{previous}}
59 void f6(typename N::X2<U>::template apply<U> *);
60 void f6(typename N::X2<U>::template apply<T> *);
61 void f6(typename ::N::X2<type>::template apply<U_type> *); // expected-error{{redeclar}}
Douglas Gregore861bac2009-08-25 22:51:20 +000062
Douglas Gregor6d7a30c2009-05-07 15:31:47 +000063 void f7(typename N::X2<T>::template apply<U> *); // expected-note{{previous}}
64 void f7(typename N::X2<U>::template apply<U> *);
65 void f7(typename N::X2<U>::template apply<T> *);
66 void f7(typename X2<type>::template apply<U_type> *); // expected-error{{redeclar}}
67
68 void f8(typename N::X2<T>::template apply<U> *); // expected-note{{previous}}
69 void f8(typename N::X2<U>::template apply<U> *);
70 void f8(typename N::X2<U>::template apply<T> *);
71 void f8(typename ::Nalias::X2<type>::template apply<U_type> *); // expected-error{{redeclar}}
Douglas Gregor6bc50582009-05-07 06:41:52 +000072};
Douglas Gregore9ceb312010-05-19 04:13:23 +000073
74namespace PR6851 {
75 template <bool v>
76 struct S;
77
78 struct N {
79 template <bool w>
80 S< S<w>::cond && 1 > foo();
81 };
82
Richard Smithbac0a0d2016-10-24 18:47:04 +000083 struct Arrow { Arrow *operator->(); int n; };
84 template<typename T> struct M {
85 Arrow a;
86 auto f() -> M<decltype(a->n)>;
87 };
88
Douglas Gregore9ceb312010-05-19 04:13:23 +000089 struct Alien;
90 bool operator&&(const Alien&, const Alien&);
91
92 template <bool w>
93 S< S<w>::cond && 1 > N::foo() { }
Richard Smithbac0a0d2016-10-24 18:47:04 +000094
95 template<typename T>
96 auto M<T>::f() -> M<decltype(a->n)> {}
Douglas Gregore9ceb312010-05-19 04:13:23 +000097}
Douglas Gregorf5b160f2010-07-13 08:37:11 +000098
99namespace PR7460 {
100 template <typename T>
101 struct TemplateClass2
102 {
103 enum { SIZE = 100 };
104 static T member[SIZE];
105 };
106
107 template <typename T>
108 T TemplateClass2<T>::member[TemplateClass2<T>::SIZE];
109}
Richard Smithaae40582014-03-13 00:28:45 +0000110
111namespace PR18275 {
112 template<typename T> struct A {
113 void f(const int);
114 void g(int);
115 void h(const T);
116 void i(T);
117 };
118
119 template<typename T>
120 void A<T>::f(int x) { x = 0; }
121
122 template<typename T>
Richard Trieuaf7d76c2015-04-11 01:53:13 +0000123 void A<T>::g(const int x) { // expected-note {{declared const here}}
124 x = 0; // expected-error {{cannot assign to variable 'x'}}
125 }
Richard Smithaae40582014-03-13 00:28:45 +0000126
127 template<typename T>
128 void A<T>::h(T) {} // FIXME: Should reject this. Type is different from prior decl if T is an array type.
129
130 template<typename T>
131 void A<T>::i(const T) {} // FIXME: Should reject this. Type is different from prior decl if T is an array type.
132
133 template struct A<int>;
134 template struct A<int[1]>;
135}
Richard Smithbc2e9712014-10-17 20:56:14 +0000136
137namespace PR21289 {
138 template<typename T> using X = int;
139 template<typename T, decltype(sizeof(0))> using Y = int;
140 template<typename ...Ts> struct S {};
141 template<typename ...Ts> void f() {
142 // This is a dependent type. It is *not* S<int>, even though it canonically
143 // contains no template parameters.
144 using Type = S<X<Ts>...>;
145 Type s;
146 using Type = S<int, int, int>;
147 }
148 void g() { f<void, void, void>(); }
149
150 template<typename ...Ts> void h(S<int>) {}
151 // Pending a core issue, it's not clear if these are redeclarations, but they
152 // are probably intended to be... even though substitution can succeed for one
153 // of them but fail for the other!
154 template<typename ...Ts> void h(S<X<Ts>...>) {} // expected-note {{previous}}
155 template<typename ...Ts> void h(S<Y<Ts, sizeof(Ts)>...>) {} // expected-error {{redefinition}}
156}