blob: 59630be508859e600f8b88ac6f6d098a6dbebf29 [file] [log] [blame]
Richard Smith764d2fe2011-12-20 02:08:33 +00001// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
Larisse Voufof73da982014-07-30 00:49:55 +00002// RUN: %clang_cc1 -fsyntax-only -std=c++1y -verify %s -DCXX1Y
3
4#ifndef CXX1Y
Richard Smith764d2fe2011-12-20 02:08:33 +00005
6template<typename T, typename U, U> using alias_ref = T;
7template<typename T, typename U, U> void func_ref() {}
8template<typename T, typename U, U> struct class_ref {};
9
10template<int N>
11struct U {
12 static int a;
13};
14
Larisse Voufob6fab262014-07-29 18:44:19 +000015template<int N> struct S; // expected-note 6{{here}}
Richard Smith764d2fe2011-12-20 02:08:33 +000016
17template<int N>
Larisse Voufob6fab262014-07-29 18:44:19 +000018int U<N>::a = S<N>::kError; // expected-error 6{{undefined}}
Richard Smith764d2fe2011-12-20 02:08:33 +000019
20template<typename T>
21void f() {
Larisse Voufob6fab262014-07-29 18:44:19 +000022 (void)alias_ref<int, int&, U<0>::a>(); // expected-note {{here}}
Richard Smith764d2fe2011-12-20 02:08:33 +000023 (void)func_ref<int, int&, U<1>::a>(); // expected-note {{here}}
24 (void)class_ref<int, int&, U<2>::a>(); // expected-note {{here}}
25};
26
Richard Smithe5945872017-01-06 22:52:53 +000027template<typename T>
28void not_instantiated() {
29 // These cases (arguably) do not require instantiation of U<i>::a.
30 (void)alias_ref<int, int&, U<3>::a>();
31 (void)func_ref<int, int&, U<4>::a>();
32 (void)class_ref<int, int&, U<5>::a>();
33};
Larisse Voufof73da982014-07-30 00:49:55 +000034
Larisse Voufob6fab262014-07-29 18:44:19 +000035template<int N>
36void fi() {
37 (void)alias_ref<int, int&, U<N>::a>(); // expected-note {{here}}
38 (void)func_ref<int, int&, U<N+1>::a>(); // expected-note {{here}}
39 (void)class_ref<int, int&, U<N+2>::a>(); // expected-note {{here}}
40};
41
Richard Smith764d2fe2011-12-20 02:08:33 +000042int main() {
Richard Smithe5945872017-01-06 22:52:53 +000043 f<int>(); // expected-note 3{{here}}
Larisse Voufob6fab262014-07-29 18:44:19 +000044 fi<10>(); // expected-note 3{{here}}
Richard Smith764d2fe2011-12-20 02:08:33 +000045}
46
47namespace N {
48 template<typename T> struct S { static int n; };
49 template<typename T> int S<T>::n = 5;
50 void g(int*);
51 template<typename T> int f() {
52 int k[S<T>::n];
53 g(k);
54 return k[3];
55 }
56 int j = f<int>();
57}
Larisse Voufob6fab262014-07-29 18:44:19 +000058
Larisse Voufof73da982014-07-30 00:49:55 +000059#else
60// expected-no-diagnostics
61
62namespace { template<typename> extern int n; }
63template<typename T> int g() { return n<int>; }
Serge Pavlov7dcc97e2016-04-19 06:19:52 +000064namespace { extern template int n<int>; }
Larisse Voufof73da982014-07-30 00:49:55 +000065
66#endif
67