recovery-expr-type.cpp
3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -frecovery-ast -frecovery-ast-type -o - %s -fsyntax-only -verify
namespace test0 {
struct Indestructible {
// Indestructible();
~Indestructible() = delete; // expected-note 2{{deleted}}
};
Indestructible make_indestructible();
void test() {
// no crash.
int s = sizeof(make_indestructible()); // expected-error {{deleted}}
constexpr int ss = sizeof(make_indestructible()); // expected-error {{deleted}}
static_assert(ss, "");
int array[ss];
}
}
namespace test1 {
constexpr int foo() { return 1; } // expected-note {{candidate function not viable}}
// verify the "not an integral constant expression" diagnostic is suppressed.
static_assert(1 == foo(1), ""); // expected-error {{no matching function}}
}
namespace test2 {
void foo(); // expected-note 3{{requires 0 arguments}}
void func() {
// verify that "field has incomplete type" diagnostic is suppressed.
typeof(foo(42)) var; // expected-error {{no matching function}}
// FIXME: suppress the "cannot initialize a variable" diagnostic.
int a = foo(1); // expected-error {{no matching function}} \
// expected-error {{cannot initialize a variable of type}}
// FIXME: suppress the "invalid application" diagnostic.
int s = sizeof(foo(42)); // expected-error {{no matching function}} \
// expected-error {{invalid application of 'sizeof'}}
};
}
namespace test3 {
template <int N>
constexpr int templated() __attribute__((enable_if(N, ""))) { // expected-note {{candidate disabled}}
return 1;
}
// verify that "constexpr variable must be initialized" diagnostic is suppressed.
constexpr int A = templated<0>(); // expected-error{{no matching function}}
template <typename T>
struct AA {
template <typename U>
static constexpr int getB() { // expected-note{{candidate template ignored}}
return 2;
}
static constexpr int foo2() {
return AA<T>::getB(); // expected-error{{no matching function for call to 'getB'}} \
// expected-note {{subexpression not valid in a constant expression}}
}
};
// FIXME: should we suppress the "be initialized by a constant expression" diagnostic?
constexpr auto x2 = AA<int>::foo2(); // expected-error {{be initialized by a constant expression}} \
// expected-note {{in instantiation of member function}} \
// expected-note {{in call to}}
}
// verify no assertion failure on violating value category.
namespace test4 {
int &&f(int); // expected-note {{candidate function not viable}}
int &&k = f(); // expected-error {{no matching function for call}}
}
// verify that "type 'double' cannot bind to a value of unrelated type 'int'" diagnostic is suppressed.
namespace test5 {
template<typename T> using U = T; // expected-note {{template parameter is declared here}}
template<typename...Ts> U<Ts...>& f(); // expected-error {{pack expansion used as argument for non-pack parameter of alias template}}
double &s1 = f(); // expected-error {{no matching function}}
}
namespace test6 {
struct T {
T() = delete; // expected-note {{has been explicitly marked deleted here}}
};
void func() {
// verify that no -Wunused-value diagnostic.
(T(T())); // expected-error {{call to deleted constructor}}
}
}
// verify the secondary diagnostic "no matching function" is emitted.
namespace test7 {
struct C {
C() = delete; // expected-note {{has been explicitly marked deleted}}
};
void f(C &); // expected-note {{candidate function not viable: expects an l-value for 1st argument}}
void test() {
f(C()); // expected-error {{call to deleted constructor}} \
expected-error {{no matching function for call}}
}
}
// verify the secondary diagnostic "cannot initialize" is emitted.
namespace test8 {
typedef int arr[];
int v = arr(); // expected-error {{array types cannot be value-initialized}} \
expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'test8::arr'}}
}