1*d8a1c6d7SOleksandr T. // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify=expected,pre26 %s 2*d8a1c6d7SOleksandr T. // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify=expected,pre26-pedantic -pedantic %s 3ef164ceeSSirraide // RUN: %clang_cc1 -std=c++2c -fsyntax-only -verify=expected,compat -Wpre-c++26-compat %s 4ef164ceeSSirraide // RUN: %clang_cc1 -std=c++2c -fsyntax-only -verify %s 5ef164ceeSSirraide 6ef164ceeSSirraide struct S { 7ef164ceeSSirraide void a() = delete; 8ef164ceeSSirraide void b() = delete(; // expected-error {{expected string literal}} expected-error {{expected ')'}} expected-note {{to match this '('}} 9ef164ceeSSirraide void c() = delete(); // expected-error {{expected string literal}} 10ef164ceeSSirraide void d() = delete(42); // expected-error {{expected string literal}} 11*d8a1c6d7SOleksandr T. 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*d8a1c6d7SOleksandr T. 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}} 13ef164ceeSSirraide 14*d8a1c6d7SOleksandr T. 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*d8a1c6d7SOleksandr T. ~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*d8a1c6d7SOleksandr T. 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*d8a1c6d7SOleksandr T. 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*d8a1c6d7SOleksandr T. 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*d8a1c6d7SOleksandr T. 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}} 20ef164ceeSSirraide }; 21ef164ceeSSirraide 22ef164ceeSSirraide struct T { 23ef164ceeSSirraide T() = delete(); // expected-error {{expected string literal}} 24ef164ceeSSirraide ~T() = delete(); // expected-error {{expected string literal}} 25ef164ceeSSirraide T(const T&) = delete(); // expected-error {{expected string literal}} 26ef164ceeSSirraide T(T&&) = delete(); // expected-error {{expected string literal}} 27ef164ceeSSirraide T& operator=(const T&) = delete(); // expected-error {{expected string literal}} 28ef164ceeSSirraide T& operator=(T&&) = delete(); // expected-error {{expected string literal}} 29ef164ceeSSirraide }; 30ef164ceeSSirraide 31ef164ceeSSirraide void a() = delete; 32ef164ceeSSirraide void b() = delete(; // expected-error {{expected string literal}} expected-error {{expected ')'}} expected-note {{to match this '('}} 33ef164ceeSSirraide void c() = delete(); // expected-error {{expected string literal}} 34ef164ceeSSirraide void d() = delete(42); // expected-error {{expected string literal}} 35*d8a1c6d7SOleksandr T. 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*d8a1c6d7SOleksandr T. 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}} 37ef164ceeSSirraide 38ef164ceeSSirraide constexpr const char *getMsg() { return "this is a message"; } 39ef164ceeSSirraide void func() = delete(getMsg()); // expected-error {{expected string literal}} 40ef164ceeSSirraide 41ef164ceeSSirraide namespace CWG2876 { 42ef164ceeSSirraide using T = void (); 43ef164ceeSSirraide using U = int; 44ef164ceeSSirraide 45ef164ceeSSirraide T a = delete ("hello"); // expected-error {{only functions can have deleted definitions}} 46ef164ceeSSirraide U b = delete ("hello"), c, d = delete ("hello"); // expected-error 2 {{only functions can have deleted definitions}} 47ef164ceeSSirraide 48ef164ceeSSirraide struct C { 49ef164ceeSSirraide T e = delete ("hello"); // expected-error {{'= delete' is a function definition and must occur in a standalone declaration}} 50ef164ceeSSirraide U f = delete ("hello"); // expected-error {{cannot delete expression of type 'const char[6]'}} 51ef164ceeSSirraide }; 52ef164ceeSSirraide } 53*d8a1c6d7SOleksandr T. 54*d8a1c6d7SOleksandr T. namespace GH109311 { 55*d8a1c6d7SOleksandr T. void f() = delete 56*d8a1c6d7SOleksandr T. #if __cpp_deleted_function >= 202403L 57*d8a1c6d7SOleksandr T. ("reason") // pre26-pedantic-warning {{'= delete' with a message is a C++2c extension}} \ 58*d8a1c6d7SOleksandr T. // compat-warning {{'= delete' with a message is incompatible with C++ standards before C++2}} 59*d8a1c6d7SOleksandr T. #endif 60*d8a1c6d7SOleksandr T. ; 61*d8a1c6d7SOleksandr T. } 62