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
6 struct Indestructible
{
8 ~Indestructible() = delete; // expected-note 2{{deleted}}
10 Indestructible
make_indestructible();
14 int s
= sizeof(make_indestructible()); // expected-error {{deleted}}
15 constexpr int ss
= sizeof(make_indestructible()); // expected-error {{deleted}}
16 static_assert(ss
, "");
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}}
28 void foo(); // expected-note 3{{requires 0 arguments}}
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'}}
45 constexpr int templated() __attribute__((enable_if(N
, ""))) { // expected-note {{candidate disabled}}
48 // verify that "constexpr variable must be initialized" diagnostic is suppressed.
49 constexpr int A
= templated
<0>(); // expected-error{{no matching function}}
54 static constexpr int getB() { // expected-note{{candidate template ignored}}
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.
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.
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}}
81 T() = delete; // expected-note {{has been explicitly marked deleted here}}
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.
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}}
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.
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'}}
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'}}
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}}
123 // Verify we do not assert()-fail here.
124 template <class T
> void foo(T
&t
);
125 template <typename T
>
130 template <typename T
= void *>
131 struct S
{ // expected-note {{candidate}}
132 S(T t
); // expected-note {{candidate}}
135 template <typename T
> S(T t
) -> S
<void *>;
138 bar(S(123)); // expected-error {{no matching conversion for functional-style cast from 'int' to 'S<void *>'}}
140 } // namespace test11
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
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'}}
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
171 void m(int (&)[undefined()]) {} // expected-error {{undeclared identifier}}
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}}
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}}