Debian Codegraph @

clang/test/Parser/cxx2c-delete-with-message.cpp

raw
1 // RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=expected,pre26 -pedantic %s
2 // RUN: %clang_cc1 -std=c++2c -fsyntax-only -verify=expected,compat -Wpre-c++26-compat %s
3 // RUN: %clang_cc1 -std=c++2c -fsyntax-only -verify %s
4
5 struct S {
6 void a() = delete;
7 void b() = delete(; // expected-error {{expected string literal}} expected-error {{expected ')'}} expected-note {{to match this '('}}
8 void c() = delete(); // expected-error {{expected string literal}}
9 void d() = delete(42); // expected-error {{expected string literal}}
10 void e() = delete("foo"[0]); // expected-error {{expected ')'}} expected-note {{to match this '('}} // pre26-warning {{'= delete' with a message is a C++2c extension}} compat-warning {{'= delete' with a message is incompatible with C++ standards before C++2c}}
11 void f() = delete("foo"); // pre26-warning {{'= delete' with a message is a C++2c extension}} compat-warning {{'= delete' with a message is incompatible with C++ standards before C++2c}}
12
13 S() = delete("foo"); // pre26-warning {{'= delete' with a message is a C++2c extension}} compat-warning {{'= delete' with a message is incompatible with C++ standards before C++2c}}
14 ~S() = delete("foo"); // pre26-warning {{'= delete' with a message is a C++2c extension}} compat-warning {{'= delete' with a message is incompatible with C++ standards before C++2c}}
15 S(const S&) = delete("foo"); // pre26-warning {{'= delete' with a message is a C++2c extension}} compat-warning {{'= delete' with a message is incompatible with C++ standards before C++2c}}
16 S(S&&) = delete("foo"); // pre26-warning {{'= delete' with a message is a C++2c extension}} compat-warning {{'= delete' with a message is incompatible with C++ standards before C++2c}}
17 S& operator=(const S&) = delete("foo"); // pre26-warning {{'= delete' with a message is a C++2c extension}} compat-warning {{'= delete' with a message is incompatible with C++ standards before C++2c}}
18 S& operator=(S&&) = delete("foo"); // pre26-warning {{'= delete' with a message is a C++2c extension}} compat-warning {{'= delete' with a message is incompatible with C++ standards before C++2c}}
19 };
20
21 struct T {
22 T() = delete(); // expected-error {{expected string literal}}
23 ~T() = delete(); // expected-error {{expected string literal}}
24 T(const T&) = delete(); // expected-error {{expected string literal}}
25 T(T&&) = delete(); // expected-error {{expected string literal}}
26 T& operator=(const T&) = delete(); // expected-error {{expected string literal}}
27 T& operator=(T&&) = delete(); // expected-error {{expected string literal}}
28 };
29
30 void a() = delete;
31 void b() = delete(; // expected-error {{expected string literal}} expected-error {{expected ')'}} expected-note {{to match this '('}}
32 void c() = delete(); // expected-error {{expected string literal}}
33 void d() = delete(42); // expected-error {{expected string literal}}
34 void e() = delete("foo"[0]); // expected-error {{expected ')'}} expected-note {{to match this '('}} // pre26-warning {{'= delete' with a message is a C++2c extension}} compat-warning {{'= delete' with a message is incompatible with C++ standards before C++2c}}
35 void f() = delete("foo"); // pre26-warning {{'= delete' with a message is a C++2c extension}} compat-warning {{'= delete' with a message is incompatible with C++ standards before C++2c}}
36
37 constexpr const char *getMsg() { return "this is a message"; }
38 void func() = delete(getMsg()); // expected-error {{expected string literal}}
39
40 namespace CWG2876 {
41 using T = void ();
42 using U = int;
43
44 T a = delete ("hello"); // expected-error {{only functions can have deleted definitions}}
45 U b = delete ("hello"), c, d = delete ("hello"); // expected-error 2 {{only functions can have deleted definitions}}
46
47 struct C {
48 T e = delete ("hello"); // expected-error {{'= delete' is a function definition and must occur in a standalone declaration}}
49 U f = delete ("hello"); // expected-error {{cannot delete expression of type 'const char[6]'}}
50 };
51 }