[ELF] Avoid make in elf::writeARMCmseImportLib
[llvm-project.git] / clang / test / SemaTemplate / dependent-template-recover.cpp
blobc7e27e8da25f16f74326b625ad2abfb1ea3eeb68
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 template<typename T, typename U, int N>
3 struct 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}}
8 t->operator+<U const, 1>(1); // expected-error{{use 'template' keyword to treat 'operator +' as a dependent template name}}
9 t->f1<int const, 2>(1); // expected-error{{use 'template' keyword to treat 'f1' as a dependent template name}}
10 t->f1<3, int const>(1); // expected-error{{missing 'template' keyword prior to dependent template name 'f1'}}
12 T::getAs<U>(); // expected-error{{use 'template' keyword to treat 'getAs' as a dependent template name}}
13 t->T::getAs<U>(); // expected-error{{use 'template' keyword to treat 'getAs' as a dependent template name}}
15 (*t).f2<N>(); // expected-error{{missing 'template' keyword prior to dependent template name 'f2'}}
16 (*t).f2<0>(); // expected-error{{missing 'template' keyword prior to dependent template name 'f2'}}
17 T::f2<0>(); // expected-error{{missing 'template' keyword prior to dependent template name 'f2'}}
18 T::f2<0, int>(0); // expected-error{{missing 'template' keyword prior to dependent template name 'f2'}}
20 T::foo<N < 2 || N >= 4>(); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
22 // If there are multiple potential template names, pick the one where there
23 // is no whitespace between the name and the '<'.
24 T::foo<T::bar < 1>(); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
25 T::foo < T::bar<1>(); // expected-error{{missing 'template' keyword prior to dependent template name 'bar'}}
27 // Prefer to diagnose a missing 'template' keyword rather than finding a non-template name.
28 xyz < T::foo < 1 > (); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
29 T::foo < xyz < 1 > (); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
31 // ... even if the whitespace suggests the other name is the template name.
32 // FIXME: Is this the right heuristic?
33 xyz<T::foo < 1>(); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
34 T::foo < xyz<1>(); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
36 sizeof T::foo < 123 > (); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
37 f(t->foo<1, 2>(), // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
38 t->bar<3, 4>()); // expected-error{{missing 'template' keyword prior to dependent template name 'bar'}}
40 int arr[] = {
41 t->baz<1, 2>(1 + 1), // ok, two comparisons
42 t->foo<1, 2>(), // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
43 t->bar<3, 4>() // FIXME: we don't recover from the previous error so don't diagnose this
47 int xyz;
50 template <typename T> void not_missing_template(T t) {
51 (T::n < 0) > (
52 ) // expected-error {{expected expression}}
55 int a = T::x < 3;
56 int b = T::y > (); // expected-error {{expected expression}}
58 void c(int = T::x < 3);
59 void d(int = T::y > ()); // expected-error {{expected expression}}
61 for (int x = t < 3 ? 1 : 2; t > (); ++t) { // expected-error {{expected expression}}
64 // FIXME: We shouldn't treat 'T::t' as a potential template-name here,
65 // because that would leave a '?' with no matching ':'.
66 // We should probably generally treat '?' ... ':' as a bracket-like
67 // construct.
68 bool k = T::t < 3 ? 1 > () : false; // expected-error {{missing 'template' keyword}} expected-error +{{}} expected-note +{{}}
71 struct MrsBadcrumble {
72 friend MrsBadcrumble operator<(void (*)(int), MrsBadcrumble);
73 friend void operator>(MrsBadcrumble, int);
74 } mb;
76 template<int N, typename T> void f(T t) {
77 t.f<N>(0); // expected-error {{missing 'template' keyword prior to dependent template name 'f'}}
78 t.T::f<N>(0); // expected-error {{missing 'template' keyword prior to dependent template name 'f'}}
79 T::g<N>(0); // expected-error {{missing 'template' keyword prior to dependent template name 'g'}}
81 // Note: no diagnostic here, this is actually valid as a comparison between
82 // the decayed pointer to Y::g<> and mb!
83 T::g<mb>(0);
85 // ... but this one must be a template-id.
86 T::g<mb, int>(0); // expected-error {{missing 'template' keyword prior to dependent template name 'g'}}
89 struct Y {
90 template <int> void f(int);
91 template <int = 0> static void g(int); // expected-warning 0-1{{extension}}
93 void q() { void (*p)(int) = Y::g; }
94 template void f<0>(Y); // expected-note {{in instantiation of}}
96 namespace PR9401 {
97 // From GCC PR c++/45558
98 template <typename S, typename T>
99 struct C
101 template <typename U>
102 struct B
104 template <typename W>
105 struct E
107 explicit E(const W &x) : w(x) {}
108 const W &w;
113 struct F;
114 template <typename X>
115 struct D
117 D() {}
120 const D<F> g;
121 template <typename S, typename T>
122 struct A
124 template <typename U>
125 struct B : C<S, T>::template B<U>
127 typedef typename C<S, T>::template B<U> V;
128 static const D<typename V::template E<D<F> > > a;
132 template <typename S, typename T>
133 template <typename U>
134 const D<typename C<S, T>::template B<U>::template E<D<F> > >
135 A<S, T>::B<U>::a = typename C<S, T>::template B<U>::template E<D<F> >(g);