Skip to content

Commit d6537a2

Browse files
committed
[Clang] Add extension+compatibility diags
1 parent 40a2330 commit d6537a2

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,12 @@ def warn_cxx98_compat_defaulted_deleted_function : Warning<
941941
"%select{defaulted|deleted}0 function definitions are incompatible with C++98">,
942942
InGroup<CXX98Compat>, DefaultIgnore;
943943

944+
def ext_delete_with_message : ExtWarn<
945+
"'= delete' with a message is a C++2c extension">, InGroup<CXX26>;
946+
def warn_cxx23_delete_with_message : Warning<
947+
"'= delete' with a message is incompatible with C++ standards before C++2c">,
948+
DefaultIgnore, InGroup<CXXPre26Compat>;
949+
944950
// C++11 default member initialization
945951
def ext_nonstatic_member_init : ExtWarn<
946952
"default member initializer for non-static data member is a C++11 "

clang/lib/Parse/ParseCXXInlineMethods.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ NamedDecl *Parser::ParseCXXInlineMethodDef(
9595
StringLiteral *Message = ParseCXXDeletedFunctionMessage();
9696
Actions.SetDeclDeleted(FnD, KWLoc, Message);
9797
Delete = true;
98+
if (Message)
99+
Diag(Message->getBeginLoc(), getLangOpts().CPlusPlus26
100+
? diag::warn_cxx23_delete_with_message
101+
: diag::ext_delete_with_message)
102+
<< Message->getSourceRange();
98103
if (auto *DeclAsFunction = dyn_cast<FunctionDecl>(FnD)) {
99104
DeclAsFunction->setRangeEnd(KWEndLoc);
100105
}

clang/lib/Parse/Parser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,11 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,
14171417
<< 1 /* deleted */;
14181418
BodyKind = Sema::FnBodyKind::Delete;
14191419
DeletedMessage = ParseCXXDeletedFunctionMessage();
1420+
if (DeletedMessage)
1421+
Diag(DeletedMessage->getBeginLoc(),
1422+
getLangOpts().CPlusPlus26 ? diag::warn_cxx23_delete_with_message
1423+
: diag::ext_delete_with_message)
1424+
<< DeletedMessage->getSourceRange();
14201425
} else if (TryConsumeToken(tok::kw_default, KWLoc)) {
14211426
Diag(KWLoc, getLangOpts().CPlusPlus11
14221427
? diag::warn_cxx98_compat_defaulted_deleted_function
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
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
13
// RUN: %clang_cc1 -std=c++2c -fsyntax-only -verify %s
24

35
struct S {
46
void a() = delete;
57
void b() = delete(; // expected-error {{expected string literal}} expected-error {{expected ')'}} expected-note {{to match this '('}}
68
void c() = delete(); // expected-error {{expected string literal}}
79
void d() = delete(42); // expected-error {{expected string literal}}
8-
void e() = delete("foo"[0]); // expected-error {{expected ')'}} expected-note {{to match this '('}}
9-
void f() = delete("foo");
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}}
1012

11-
S() = delete("foo");
12-
~S() = delete("foo");
13-
S(const S&) = delete("foo");
14-
S(S&&) = delete("foo");
15-
S& operator=(const S&) = delete("foo");
16-
S& operator=(S&&) = delete("foo");
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}}
1719
};
1820

1921
struct T {
@@ -29,5 +31,5 @@ void a() = delete;
2931
void b() = delete(; // expected-error {{expected string literal}} expected-error {{expected ')'}} expected-note {{to match this '('}}
3032
void c() = delete(); // expected-error {{expected string literal}}
3133
void d() = delete(42); // expected-error {{expected string literal}}
32-
void e() = delete("foo"[0]); // expected-error {{expected ')'}} expected-note {{to match this '('}}
33-
void f() = delete("foo");
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}}

0 commit comments

Comments
 (0)