blob: ac1623041719bb5f395f17a9b073d58ecf1f37d6 [file] [log] [blame]
Douglas Gregor786123d2010-05-21 23:18:07 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2template<typename T, typename U, int N>
3struct X {
4 void f(T* t) {
5 t->f0<U>(); // expected-error{{use 'template' keyword to treat 'f0' as a dependent template name}}
6 t->f0<int>(); // expected-error{{use 'template' keyword to treat 'f0' as a dependent template name}}
7
8 t->operator+<U const, 1>(); // expected-error{{use 'template' keyword to treat 'operator +' as a dependent template name}}
9 t->f1<int const, 2>(); // expected-error{{use 'template' keyword to treat 'f1' as a dependent template name}}
10
Douglas Gregor20c38a72010-05-21 23:43:39 +000011 T::getAs<U>(); // expected-error{{use 'template' keyword to treat 'getAs' as a dependent template name}}
12 t->T::getAs<U>(); // expected-error{{use 'template' keyword to treat 'getAs' as a dependent template name}}
13
Douglas Gregor786123d2010-05-21 23:18:07 +000014 // FIXME: We can't recover from these yet
15 (*t).f2<N>(); // expected-error{{expected expression}}
16 (*t).f2<0>(); // expected-error{{expected expression}}
17 }
18};
Douglas Gregor23648d72011-03-04 18:53:13 +000019
Richard Smith17c59472017-06-07 00:29:44 +000020struct MrsBadcrumble {
21 friend MrsBadcrumble operator<(void (*)(int), MrsBadcrumble);
22 friend void operator>(MrsBadcrumble, int);
23} mb;
24
25template<int N, typename T> void f(T t) {
26 t.f<N>(0); // expected-error {{missing 'template' keyword prior to dependent template name 'f'}}
27 t.T::f<N>(0); // expected-error {{missing 'template' keyword prior to dependent template name 'f'}}
28 T::g<N>(0); // expected-error {{missing 'template' keyword prior to dependent template name 'g'}}
29
30 // Note: no diagnostic here, this is actually valid as a comparison between
31 // the decayed pointer to Y::g<> and mb!
32 T::g<mb>(0);
33}
34
35struct Y {
36 template <int> void f(int);
37 template <int = 0> static void g(int); // expected-warning 0-1{{extension}}
38};
39void q() { void (*p)(int) = Y::g; }
40template void f<0>(Y); // expected-note {{in instantiation of}}
41
Douglas Gregor23648d72011-03-04 18:53:13 +000042namespace PR9401 {
43 // From GCC PR c++/45558
44 template <typename S, typename T>
45 struct C
46 {
47 template <typename U>
48 struct B
49 {
50 template <typename W>
51 struct E
52 {
53 explicit E(const W &x) : w(x) {}
54 const W &w;
55 };
56 };
57 };
58
59 struct F;
60 template <typename X>
61 struct D
62 {
63 D() {}
64 };
65
66 const D<F> g;
67 template <typename S, typename T>
68 struct A
69 {
70 template <typename U>
71 struct B : C<S, T>::template B<U>
72 {
73 typedef typename C<S, T>::template B<U> V;
74 static const D<typename V::template E<D<F> > > a;
75 };
76 };
77
78 template <typename S, typename T>
79 template <typename U>
80 const D<typename C<S, T>::template B<U>::template E<D<F> > >
81 A<S, T>::B<U>::a = typename C<S, T>::template B<U>::template E<D<F> >(g);
82}