[lld][WebAssembly] Reinstate mistakenly disabled test. NFC
[llvm-project.git] / clang / test / SemaCXX / recovery-expr-type.cpp
blob94b275c9a362fdb78735e361131398f2d00e1e5f
1 // RUN: %clang_cc1 -triple=x86_64-unknown-unknown -frecovery-ast -frecovery-ast-type -o - %s -std=gnu++17 -fsyntax-only -verify
3 namespace test0 {
4 struct Indestructible {
5 // Indestructible();
6 ~Indestructible() = delete; // expected-note 2{{deleted}}
7 };
8 Indestructible make_indestructible();
10 void test() {
11 // no crash.
12 int s = sizeof(make_indestructible()); // expected-error {{deleted}}
13 constexpr int ss = sizeof(make_indestructible()); // expected-error {{deleted}}
14 static_assert(ss, "");
15 int array[ss];
19 namespace test1 {
20 constexpr int foo() { return 1; } // expected-note {{candidate function not viable}}
21 // verify the "not an integral constant expression" diagnostic is suppressed.
22 static_assert(1 == foo(1), ""); // expected-error {{no matching function}}
25 namespace test2 {
26 void foo(); // expected-note 3{{requires 0 arguments}}
27 void func() {
28 // verify that "field has incomplete type" diagnostic is suppressed.
29 typeof(foo(42)) var; // expected-error {{no matching function}} \
31 // FIXME: suppress the "cannot initialize a variable" diagnostic.
32 int a = foo(1); // expected-error {{no matching function}} \
33 // expected-error {{cannot initialize a variable of type}}
35 // FIXME: suppress the "invalid application" diagnostic.
36 int s = sizeof(foo(42)); // expected-error {{no matching function}} \
37 // expected-error {{invalid application of 'sizeof'}}
41 namespace test3 {
42 template <int N>
43 constexpr int templated() __attribute__((enable_if(N, ""))) { // expected-note {{candidate disabled}}
44 return 1;
46 // verify that "constexpr variable must be initialized" diagnostic is suppressed.
47 constexpr int A = templated<0>(); // expected-error{{no matching function}}
49 template <typename T>
50 struct AA {
51 template <typename U>
52 static constexpr int getB() { // expected-note{{candidate template ignored}}
53 return 2;
55 static constexpr int foo2() {
56 return AA<T>::getB(); // expected-error{{no matching function for call to 'getB'}}
59 // FIXME: should we suppress the "be initialized by a constant expression" diagnostic?
60 constexpr auto x2 = AA<int>::foo2(); // expected-error {{be initialized by a constant expression}} \
61 // expected-note {{in instantiation of member function}}
64 // verify no assertion failure on violating value category.
65 namespace test4 {
66 int &&f(int); // expected-note {{candidate function not viable}}
67 int &&k = f(); // expected-error {{no matching function for call}}
70 // verify that "type 'double' cannot bind to a value of unrelated type 'int'" diagnostic is suppressed.
71 namespace test5 {
72 template<typename T> using U = T; // expected-note {{template parameter is declared here}}
73 template<typename...Ts> U<Ts...>& f(); // expected-error {{pack expansion used as argument for non-pack parameter of alias template}}
74 double &s1 = f(); // expected-error {{no matching function}}
77 namespace test6 {
78 struct T {
79 T() = delete; // expected-note {{has been explicitly marked deleted here}}
82 void func() {
83 // verify that no -Wunused-value diagnostic.
84 (T(T())); // expected-error {{call to deleted constructor}}
88 // verify the secondary diagnostic "no matching function" is emitted.
89 namespace test7 {
90 struct C {
91 C() = delete; // expected-note {{has been explicitly marked deleted}}
93 void f(C &); // expected-note {{candidate function not viable: expects an lvalue for 1st argument}}
94 void test() {
95 f(C()); // expected-error {{call to deleted constructor}} \
96 expected-error {{no matching function for call}}
100 // verify the secondary diagnostic "cannot initialize" is emitted.
101 namespace test8 {
102 typedef int arr[];
103 int v = arr(); // expected-error {{array types cannot be value-initialized}} \
104 expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'test8::arr'}}
107 namespace test9 {
108 auto f(); // expected-note {{candidate function not viable}}
109 // verify no crash on evaluating the size of undeduced auto type.
110 static_assert(sizeof(f(1)), ""); // expected-error {{no matching function for call to 'f'}}
113 namespace test10 {
114 // Ensure we don't assert here.
115 int f(); // expected-note {{candidate}}
116 template<typename T> const int k = f(T()); // expected-error {{no matching function}}
117 static_assert(k<int> == 1, ""); // expected-note {{instantiation of}}
120 namespace test11 {
121 // Verify we do not assert()-fail here.
122 template <class T> void foo(T &t);
123 template <typename T>
124 void bar(T t) {
125 foo(t);
128 template <typename T = void *>
129 struct S { // expected-note {{candidate}}
130 S(T t); // expected-note {{candidate}}
131 ~S();
133 template <typename T> S(T t) -> S<void *>;
135 void baz() {
136 bar(S(123)); // expected-error {{no matching conversion for functional-style cast from 'int' to 'S<void *>'}}
138 } // namespace test11
140 namespace test12 {
141 // Verify we do not crash.
142 int fun(int *foo = no_such_function()); // expected-error {{undeclared identifier}}
143 void crash1() { fun(); }
144 void crash2() { constexpr int s = fun(); }
145 } // namespace test12
147 namespace test13 {
148 enum Circular { // expected-note {{not complete until the closing '}'}}
149 Circular_A = Circular(1), // expected-error {{'test13::Circular' is an incomplete type}}
151 // Enumerators can be evaluated (they evaluate as zero, but we don't care).
152 static_assert(Circular_A == 0 && Circular_A != 0, ""); // expected-error {{static_assert failed}}