[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaCXX / recovery-expr-type.cpp
blob479039f2847998f56c3acd9ad6b2121cc02d3c0d
1 // RUN: %clang_cc1 -triple=x86_64-unknown-unknown -o - %s -std=gnu++17 -fsyntax-only -verify
2 // RUN: %clang_cc1 -triple=x86_64-unknown-unknown -o - %s -std=gnu++20 -fsyntax-only -verify
5 namespace test0 {
6 struct Indestructible {
7 // Indestructible();
8 ~Indestructible() = delete; // expected-note 2{{deleted}}
9 };
10 Indestructible make_indestructible();
12 void test() {
13 // no crash.
14 int s = sizeof(make_indestructible()); // expected-error {{deleted}}
15 constexpr int ss = sizeof(make_indestructible()); // expected-error {{deleted}}
16 static_assert(ss, "");
17 int array[ss];
21 namespace test1 {
22 constexpr int foo() { return 1; } // expected-note {{candidate function not viable}}
23 // verify the "not an integral constant expression" diagnostic is suppressed.
24 static_assert(1 == foo(1), ""); // expected-error {{no matching function}}
27 namespace test2 {
28 void foo(); // expected-note 3{{requires 0 arguments}}
29 void func() {
30 // verify that "field has incomplete type" diagnostic is suppressed.
31 typeof(foo(42)) var; // expected-error {{no matching function}} \
33 // FIXME: suppress the "cannot initialize a variable" diagnostic.
34 int a = foo(1); // expected-error {{no matching function}} \
35 // expected-error {{cannot initialize a variable of type}}
37 // FIXME: suppress the "invalid application" diagnostic.
38 int s = sizeof(foo(42)); // expected-error {{no matching function}} \
39 // expected-error {{invalid application of 'sizeof'}}
43 namespace test3 {
44 template <int N>
45 constexpr int templated() __attribute__((enable_if(N, ""))) { // expected-note {{candidate disabled}}
46 return 1;
48 // verify that "constexpr variable must be initialized" diagnostic is suppressed.
49 constexpr int A = templated<0>(); // expected-error{{no matching function}}
51 template <typename T>
52 struct AA {
53 template <typename U>
54 static constexpr int getB() { // expected-note{{candidate template ignored}}
55 return 2;
57 static constexpr int foo2() {
58 return AA<T>::getB(); // expected-error{{no matching function for call to 'getB'}}
61 // FIXME: should we suppress the "be initialized by a constant expression" diagnostic?
62 constexpr auto x2 = AA<int>::foo2(); // expected-error {{be initialized by a constant expression}} \
63 // expected-note {{in instantiation of member function}}
66 // verify no assertion failure on violating value category.
67 namespace test4 {
68 int &&f(int); // expected-note {{candidate function not viable}}
69 int &&k = f(); // expected-error {{no matching function for call}}
72 // verify that "type 'double' cannot bind to a value of unrelated type 'int'" diagnostic is suppressed.
73 namespace test5 {
74 template<typename T> using U = T; // expected-note {{template parameter is declared here}}
75 template<typename...Ts> U<Ts...>& f(); // expected-error {{pack expansion used as argument for non-pack parameter of alias template}}
76 double &s1 = f(); // expected-error {{no matching function}}
79 namespace test6 {
80 struct T {
81 T() = delete; // expected-note {{has been explicitly marked deleted here}}
84 void func() {
85 // verify that no -Wunused-value diagnostic.
86 (T(T())); // expected-error {{call to deleted constructor}}
90 // verify the secondary diagnostic "no matching function" is emitted.
91 namespace test7 {
92 struct C {
93 C() = delete; // expected-note {{has been explicitly marked deleted}}
95 void f(C &); // expected-note {{candidate function not viable: expects an lvalue for 1st argument}}
96 void test() {
97 f(C()); // expected-error {{call to deleted constructor}} \
98 expected-error {{no matching function for call}}
102 // verify the secondary diagnostic "cannot initialize" is emitted.
103 namespace test8 {
104 typedef int arr[];
105 int v = arr(); // expected-error {{array types cannot be value-initialized}} \
106 expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'arr'}}
109 namespace test9 {
110 auto f(); // expected-note {{candidate function not viable}}
111 // verify no crash on evaluating the size of undeduced auto type.
112 static_assert(sizeof(f(1)), ""); // expected-error {{no matching function for call to 'f'}}
115 namespace test10 {
116 // Ensure we don't assert here.
117 int f(); // expected-note {{candidate}}
118 template<typename T> const int k = f(T()); // expected-error {{no matching function}}
119 static_assert(k<int> == 1, ""); // expected-note {{instantiation of}}
122 namespace test11 {
123 // Verify we do not assert()-fail here.
124 template <class T> void foo(T &t);
125 template <typename T>
126 void bar(T t) {
127 foo(t);
130 template <typename T = void *>
131 struct S { // expected-note {{candidate}}
132 S(T t); // expected-note {{candidate}}
133 ~S();
135 template <typename T> S(T t) -> S<void *>;
137 void baz() {
138 bar(S(123)); // expected-error {{no matching conversion for functional-style cast from 'int' to 'S<void *>'}}
140 } // namespace test11
142 namespace test12 {
143 // Verify we do not crash.
144 int fun(int *foo = no_such_function()); // expected-error {{undeclared identifier}}
145 void crash1() { fun(); }
146 void crash2() { constexpr int s = fun(); }
147 } // namespace test12
149 namespace test13 {
150 enum Circular { // expected-note {{not complete until the closing '}'}}
151 Circular_A = Circular(1), // expected-error {{'Circular' is an incomplete type}}
153 // Enumerators can be evaluated (they evaluate as zero, but we don't care).
154 static_assert(Circular_A == 0 && Circular_A != 0, ""); // expected-error {{static assertion failed}} \
155 // expected-note {{evaluates to '0 != 0'}}
158 namespace test14 {
159 extern "C" void *memset(void *, int b, unsigned long) {
160 int * const c(undef()); // expected-error {{undeclared identifier}}
161 // Verify we do not crash on evaluating *c whose initializer is a NULL-type ParenListExpr!
162 memset(c, 0, *c); // crash1
164 b = __builtin_object_size(c, 0); // crash2
168 namespace test15 {
169 void f() {
170 struct {
171 void m(int (&)[undefined()]) {} // expected-error {{undeclared identifier}}
172 } S;
173 S.m(1); // no crash
177 namespace test16 {
178 // verify we do not crash on incomplete class type.
179 template<typename T, typename U> struct A; // expected-note 5{{template is declared here}}
180 A<int, int> foo() { // expected-error {{implicit instantiation of undefined template}}
181 if (1 == 1)
182 return A<int, int>{1}; // expected-error 2{{implicit instantiation of undefined template}}
183 return A<int, int>(1); // expected-error 2{{implicit instantiation of undefined template}}