[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Parser / cxx2c-delete-with-message.cpp
blobd2d5ccf4623c9c1abd8fb618e64f5e647a96e001
1 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify=expected,pre26 %s
2 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify=expected,pre26-pedantic -pedantic %s
3 // RUN: %clang_cc1 -std=c++2c -fsyntax-only -verify=expected,compat -Wpre-c++26-compat %s
4 // RUN: %clang_cc1 -std=c++2c -fsyntax-only -verify %s
6 struct S {
7 void a() = delete;
8 void b() = delete(; // expected-error {{expected string literal}} expected-error {{expected ')'}} expected-note {{to match this '('}}
9 void c() = delete(); // expected-error {{expected string literal}}
10 void d() = delete(42); // expected-error {{expected string literal}}
11 void e() = delete("foo"[0]); // expected-error {{expected ')'}} expected-note {{to match this '('}} // pre26-pedantic-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 void f() = delete("foo"); // pre26-pedantic-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-pedantic-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() = delete("foo"); // pre26-pedantic-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(const S&) = delete("foo"); // pre26-pedantic-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(S&&) = delete("foo"); // pre26-pedantic-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=(const S&) = delete("foo"); // pre26-pedantic-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 S& operator=(S&&) = delete("foo"); // pre26-pedantic-warning {{'= delete' with a message is a C++2c extension}} compat-warning {{'= delete' with a message is incompatible with C++ standards before C++2c}}
22 struct T {
23 T() = delete(); // expected-error {{expected string literal}}
24 ~T() = delete(); // expected-error {{expected string literal}}
25 T(const T&) = delete(); // expected-error {{expected string literal}}
26 T(T&&) = delete(); // expected-error {{expected string literal}}
27 T& operator=(const T&) = delete(); // expected-error {{expected string literal}}
28 T& operator=(T&&) = delete(); // expected-error {{expected string literal}}
31 void a() = delete;
32 void b() = delete(; // expected-error {{expected string literal}} expected-error {{expected ')'}} expected-note {{to match this '('}}
33 void c() = delete(); // expected-error {{expected string literal}}
34 void d() = delete(42); // expected-error {{expected string literal}}
35 void e() = delete("foo"[0]); // expected-error {{expected ')'}} expected-note {{to match this '('}} // pre26-pedantic-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 void f() = delete("foo"); // pre26-pedantic-warning {{'= delete' with a message is a C++2c extension}} compat-warning {{'= delete' with a message is incompatible with C++ standards before C++2c}}
38 constexpr const char *getMsg() { return "this is a message"; }
39 void func() = delete(getMsg()); // expected-error {{expected string literal}}
41 namespace CWG2876 {
42 using T = void ();
43 using U = int;
45 T a = delete ("hello"); // expected-error {{only functions can have deleted definitions}}
46 U b = delete ("hello"), c, d = delete ("hello"); // expected-error 2 {{only functions can have deleted definitions}}
48 struct C {
49 T e = delete ("hello"); // expected-error {{'= delete' is a function definition and must occur in a standalone declaration}}
50 U f = delete ("hello"); // expected-error {{cannot delete expression of type 'const char[6]'}}
54 namespace GH109311 {
55 void f() = delete
56 #if __cpp_deleted_function >= 202403L
57 ("reason") // pre26-pedantic-warning {{'= delete' with a message is a C++2c extension}} \
58 // compat-warning {{'= delete' with a message is incompatible with C++ standards before C++2}}
59 #endif