Skip to content

Commit 36f8029

Browse files
committed
[Clang][P1061] Add proper C++ compatability warnings
1 parent 5751d2f commit 36f8029

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,8 +1104,11 @@ def err_binding_multiple_ellipses : Error<
11041104
def note_previous_ellipsis : Note<
11051105
"previous binding pack specified here">;
11061106
def ext_cxx_binding_pack : ExtWarn<
1107-
"structured binding pack is incompatible with C++ standards before C++2c">,
1107+
"structured binding packs are a C++2c extension ">,
11081108
InGroup<CXX26>;
1109+
def warn_cxx23_compat_binding_pack : Warning<
1110+
"structured binding packs are incompatible with C++ standards before C++2c">,
1111+
InGroup<CXXPre26Compat>, DefaultIgnore;
11091112
def err_capture_default_first : Error<
11101113
"capture default must be first">;
11111114
def ext_decl_attrs_on_lambda : ExtWarn<

clang/lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7347,8 +7347,8 @@ void Parser::ParseDecompositionDeclarator(Declarator &D) {
73477347
SourceLocation EllipsisLoc;
73487348

73497349
if (Tok.is(tok::ellipsis)) {
7350-
if (!getLangOpts().CPlusPlus26)
7351-
Diag(Tok, diag::ext_cxx_binding_pack);
7350+
Diag(Tok, getLangOpts().CPlusPlus26 ? diag::warn_cxx23_compat_binding_pack
7351+
: diag::ext_cxx_binding_pack);
73527352
if (PrevEllipsisLoc.isValid()) {
73537353
Diag(Tok, diag::err_binding_multiple_ellipses);
73547354
Diag(PrevEllipsisLoc, diag::note_previous_ellipsis);
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
// RUN: %clang_cc1 -fsyntax-only -std=c++26 %s -verify=nontemplate
2-
// RUN: %clang_cc1 -fsyntax-only %s -verify=nontemplate,compat
1+
// RUN: %clang_cc1 -std=c++26 -fsyntax-only %s -verify=nontemplate
2+
// RUN: %clang_cc1 -std=c++2c -verify=cxx26,nontemplate -fsyntax-only -Wpre-c++26-compat %s
3+
// RUN: %clang_cc1 -std=c++23 -verify=cxx23,nontemplate -fsyntax-only -Wc++26-extensions %s
34

45
void decompose_array() {
56
int arr[4] = {1, 2, 3, 6};
6-
auto [x, ...rest, y] = arr; // nontemplate-error{{pack declaration outside of template}} \
7-
// compat-warning{{structured binding pack is incompatible with C++ standards before C++2c}}
7+
// cxx26-warning@+3 {{structured binding packs are incompatible with C++ standards before C++2c}}
8+
// cxx23-warning@+2 {{structured binding packs are a C++2c extension}}
9+
// nontemplate-error@+1 {{pack declaration outside of template}}
10+
auto [x, ...rest, y] = arr;
811
}

0 commit comments

Comments
 (0)