xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/PR10177.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -std=c++1y -verify %s -DCXX1Y
3*0a6a1f1dSLionel Sambuc 
4*0a6a1f1dSLionel Sambuc #ifndef CXX1Y
5f4a2713aSLionel Sambuc 
6f4a2713aSLionel Sambuc template<typename T, typename U, U> using alias_ref = T;
func_ref()7f4a2713aSLionel Sambuc template<typename T, typename U, U> void func_ref() {}
8f4a2713aSLionel Sambuc template<typename T, typename U, U> struct class_ref {};
9f4a2713aSLionel Sambuc 
10f4a2713aSLionel Sambuc template<int N>
11f4a2713aSLionel Sambuc struct U {
12f4a2713aSLionel Sambuc   static int a;
13f4a2713aSLionel Sambuc };
14f4a2713aSLionel Sambuc 
15*0a6a1f1dSLionel Sambuc template<int N> struct S; // expected-note 6{{here}}
16f4a2713aSLionel Sambuc 
17f4a2713aSLionel Sambuc template<int N>
18*0a6a1f1dSLionel Sambuc int U<N>::a = S<N>::kError; // expected-error 6{{undefined}}
19f4a2713aSLionel Sambuc 
20f4a2713aSLionel Sambuc template<typename T>
f()21f4a2713aSLionel Sambuc void f() {
22*0a6a1f1dSLionel Sambuc   (void)alias_ref<int, int&, U<0>::a>(); // expected-note {{here}}
23f4a2713aSLionel Sambuc   (void)func_ref<int, int&, U<1>::a>(); // expected-note {{here}}
24f4a2713aSLionel Sambuc   (void)class_ref<int, int&, U<2>::a>(); // expected-note {{here}}
25f4a2713aSLionel Sambuc };
26f4a2713aSLionel Sambuc 
27*0a6a1f1dSLionel Sambuc 
28*0a6a1f1dSLionel Sambuc template<int N>
fi()29*0a6a1f1dSLionel Sambuc void fi() {
30*0a6a1f1dSLionel Sambuc   (void)alias_ref<int, int&, U<N>::a>(); // expected-note {{here}}
31*0a6a1f1dSLionel Sambuc   (void)func_ref<int, int&, U<N+1>::a>(); // expected-note {{here}}
32*0a6a1f1dSLionel Sambuc   (void)class_ref<int, int&, U<N+2>::a>(); // expected-note {{here}}
33*0a6a1f1dSLionel Sambuc };
34*0a6a1f1dSLionel Sambuc 
main()35f4a2713aSLionel Sambuc int main() {
36*0a6a1f1dSLionel Sambuc   f<int>();   // NOTE: Non-dependent name uses are type-checked at template definition time.
37*0a6a1f1dSLionel Sambuc   fi<10>();   // expected-note 3{{here}}
38f4a2713aSLionel Sambuc }
39f4a2713aSLionel Sambuc 
40f4a2713aSLionel Sambuc namespace N {
41f4a2713aSLionel Sambuc   template<typename T> struct S { static int n; };
42f4a2713aSLionel Sambuc   template<typename T> int S<T>::n = 5;
43f4a2713aSLionel Sambuc   void g(int*);
f()44f4a2713aSLionel Sambuc   template<typename T> int f() {
45f4a2713aSLionel Sambuc     int k[S<T>::n];
46f4a2713aSLionel Sambuc     g(k);
47f4a2713aSLionel Sambuc     return k[3];
48f4a2713aSLionel Sambuc   }
49f4a2713aSLionel Sambuc   int j = f<int>();
50f4a2713aSLionel Sambuc }
51*0a6a1f1dSLionel Sambuc 
52*0a6a1f1dSLionel Sambuc #else
53*0a6a1f1dSLionel Sambuc // expected-no-diagnostics
54*0a6a1f1dSLionel Sambuc 
55*0a6a1f1dSLionel Sambuc namespace { template<typename> extern int n; }
g()56*0a6a1f1dSLionel Sambuc template<typename T> int g() { return n<int>; }
57*0a6a1f1dSLionel Sambuc 
58*0a6a1f1dSLionel Sambuc #endif
59*0a6a1f1dSLionel Sambuc 
60