1 // RUN: %clang_cc1 -triple=x86_64-unknown-unknown -o - %s -std=gnu++17 -fsyntax-only -verify -fexperimental-new-constant-interpreter
2 // RUN: %clang_cc1 -triple=x86_64-unknown-unknown -o - %s -std=gnu++20 -fsyntax-only -verify -fexperimental-new-constant-interpreter
3 // RUN: %clang_cc1 -triple=x86_64-unknown-unknown -o - %s -std=gnu++17 -fsyntax-only -verify
4 // RUN: %clang_cc1 -triple=x86_64-unknown-unknown -o - %s -std=gnu++20 -fsyntax-only -verify
8 struct Indestructible
{
10 ~Indestructible() = delete; // expected-note 2{{deleted}}
12 Indestructible
make_indestructible();
16 int s
= sizeof(make_indestructible()); // expected-error {{deleted}}
17 constexpr int ss
= sizeof(make_indestructible()); // expected-error {{deleted}}
18 static_assert(ss
, "");
24 constexpr int foo() { return 1; } // expected-note {{candidate function not viable}}
25 // verify the "not an integral constant expression" diagnostic is suppressed.
26 static_assert(1 == foo(1), ""); // expected-error {{no matching function}}
30 void foo(); // expected-note 3{{requires 0 arguments}}
32 // verify that "field has incomplete type" diagnostic is suppressed.
33 typeof(foo(42)) var
; // expected-error {{no matching function}} \
35 // FIXME: suppress the "cannot initialize a variable" diagnostic.
36 int a
= foo(1); // expected-error {{no matching function}} \
37 // expected-error {{cannot initialize a variable of type}}
39 // FIXME: suppress the "invalid application" diagnostic.
40 int s
= sizeof(foo(42)); // expected-error {{no matching function}} \
41 // expected-error {{invalid application of 'sizeof'}}
47 constexpr int templated() __attribute__((enable_if(N
, ""))) { // expected-note {{candidate disabled}}
50 // verify that "constexpr variable must be initialized" diagnostic is suppressed.
51 constexpr int A
= templated
<0>(); // expected-error{{no matching function}}
56 static constexpr int getB() { // expected-note{{candidate template ignored}}
59 static constexpr int foo2() {
60 return AA
<T
>::getB(); // expected-error{{no matching function for call to 'getB'}}
63 // FIXME: should we suppress the "be initialized by a constant expression" diagnostic?
64 constexpr auto x2
= AA
<int>::foo2(); // expected-error {{be initialized by a constant expression}} \
65 // expected-note {{in instantiation of member function}}
68 // verify no assertion failure on violating value category.
70 int &&f(int); // expected-note {{candidate function not viable}}
71 int &&k
= f(); // expected-error {{no matching function for call}}
74 // verify that "type 'double' cannot bind to a value of unrelated type 'int'" diagnostic is suppressed.
76 template<typename T
> using U
= T
; // expected-note {{template parameter is declared here}}
77 template<typename
...Ts
> U
<Ts
...>& f(); // expected-error {{pack expansion used as argument for non-pack parameter of alias template}}
78 double &s1
= f(); // expected-error {{no matching function}}
83 T() = delete; // expected-note {{has been explicitly marked deleted here}}
87 // verify that no -Wunused-value diagnostic.
88 (T(T())); // expected-error {{call to deleted constructor}}
92 // verify the secondary diagnostic "no matching function" is emitted.
95 C() = delete; // expected-note {{has been explicitly marked deleted}}
97 void f(C
&); // expected-note {{candidate function not viable: expects an lvalue for 1st argument}}
99 f(C()); // expected-error {{call to deleted constructor}} \
100 expected
-error
{{no matching function
for call
}}
104 // verify the secondary diagnostic "cannot initialize" is emitted.
107 int v
= arr(); // expected-error {{array types cannot be value-initialized}} \
108 expected
-error
{{cannot initialize a variable of type
'int' with an rvalue of type
'arr'}}
112 auto f(); // expected-note {{candidate function not viable}}
113 // verify no crash on evaluating the size of undeduced auto type.
114 static_assert(sizeof(f(1)), ""); // expected-error {{no matching function for call to 'f'}}
118 // Ensure we don't assert here.
119 int f(); // expected-note {{candidate}}
120 template<typename T
> const int k
= f(T()); // expected-error {{no matching function}}
121 static_assert(k
<int> == 1, ""); // expected-note {{instantiation of}}
125 // Verify we do not assert()-fail here.
126 template <class T
> void foo(T
&t
);
127 template <typename T
>
132 template <typename T
= void *>
133 struct S
{ // expected-note {{candidate}}
134 S(T t
); // expected-note {{candidate}}
137 template <typename T
> S(T t
) -> S
<void *>;
140 bar(S(123)); // expected-error {{no matching conversion for functional-style cast from 'int' to 'S<void *>'}}
142 } // namespace test11
145 // Verify we do not crash.
146 int fun(int *foo
= no_such_function()); // expected-error {{undeclared identifier}}
147 void crash1() { fun(); }
148 void crash2() { constexpr int s
= fun(); }
149 } // namespace test12
152 enum Circular
{ // expected-note {{not complete until the closing '}'}}
153 Circular_A
= Circular(1), // expected-error {{'Circular' is an incomplete type}}
155 // Enumerators can be evaluated (they evaluate as zero, but we don't care).
156 static_assert(Circular_A
== 0 && Circular_A
!= 0, ""); // expected-error {{static assertion failed}} \
157 // expected-note {{evaluates to '0 != 0'}}
161 extern "C" void *memset(void *, int b
, unsigned long) {
162 int * const c(undef()); // expected-error {{undeclared identifier}}
163 // Verify we do not crash on evaluating *c whose initializer is a NULL-type ParenListExpr!
164 memset(c
, 0, *c
); // crash1
166 b
= __builtin_object_size(c
, 0); // crash2
173 void m(int (&)[undefined()]) {} // expected-error {{undeclared identifier}}
180 // verify we do not crash on incomplete class type.
181 template<typename T
, typename U
> struct A
; // expected-note 5{{template is declared here}}
182 A
<int, int> foo() { // expected-error {{implicit instantiation of undefined template}}
184 return A
<int, int>{1}; // expected-error 2{{implicit instantiation of undefined template}}
185 return A
<int, int>(1); // expected-error 2{{implicit instantiation of undefined template}}