Debian Codegraph @

clang/test/SemaTemplate/recovery-crash.cpp

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4
5 // Clang used to crash trying to recover while adding 'this->' before Work(x);
6
7 template <typename> struct A {
8 static void Work(int); // expected-note{{here}}
9 };
10
11 template <typename T> struct B : public A<T> {
12 template <typename T2> B(T2 x) {
13 Work(x); // expected-error{{explicit qualification required}}
14 }
15 };
16
17 void Test() {
18 B<int> b(0); // expected-note{{in instantiation of function template}}
19 }
20
21
22 // Don't crash here.
23 namespace PR16134 {
24 template <class P> struct S // expected-error {{expected ';'}}
25 template <> static S<Q>::f() // expected-error +{{}}
26 }
27
28 namespace PR16225 {
29 template <typename T> void f();
30 template <typename C> void g(C*) {
31 struct LocalStruct : UnknownBase<Mumble, C> { }; // expected-error {{use of undeclared identifier 'Mumble'}}
32 f<LocalStruct>();
33 #if __cplusplus <= 199711L
34 // expected-warning@-2 {{template argument uses local type 'LocalStruct'}}
35 // expected-note@-3 {{while substituting explicitly-specified template arguments}}
36 #endif
37 struct LocalStruct2 : UnknownBase<C> { }; // expected-error {{no template named 'UnknownBase'}}
38 }
39 struct S;
40 void h() {
41 g<S>(0);
42 #if __cplusplus <= 199711L
43 // expected-note@-2 {{in instantiation of function template specialization}}
44 #endif
45 }
46 }
47
48 namespace test1 {
49 template <typename> class ArraySlice {};
50 class Foo;
51 class NonTemplateClass { // #defined-here
52 void MemberFunction(ArraySlice<Foo>, int);
53 template <class T> void MemberFuncTemplate(ArraySlice<T>, int);
54 };
55 void NonTemplateClass::MemberFunction(ArraySlice<Foo> resource_data,
56 int now) {
57 // expected-note@+1 {{in instantiation of function template specialization 'test1::NonTemplateClass::MemberFuncTemplate<test1::Foo>'}}
58 MemberFuncTemplate(resource_data, now);
59 }
60 template <class T>
61 void NonTemplateClass::MemberFuncTemplate(ArraySlice<T> resource_data, int) {
62 // expected-error@+1 {{member 'UndeclaredMethod' used before its declaration}}
63 UndeclaredMethod(resource_data);
64 }
65 // expected-error@+3 {{out-of-line definition of 'UndeclaredMethod' does not match any declaration}}
66 // expected-note@+2 {{member is declared here}}
67 // expected-note@#defined-here {{defined here}}
68 void NonTemplateClass::UndeclaredMethod() {}
69 }
70
71 namespace GH135621 {
72 template <class T> struct S {};
73 // expected-note@-1 {{class template declared here}}
74 template <class T2> void f() {
75 S<T2>::template S<int>;
76 // expected-error@-1 {{'S' is expected to be a non-type template, but instantiated to a class template}}
77 }
78 template void f<int>();
79 // expected-note@-1 {{requested here}}
80 } // namespace GH135621