Skip to content

Commit

Permalink
[Clang][P1061] Add proper C++ compatability warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ricejasonf committed Jan 29, 2025
1 parent 5751d2f commit 36f8029
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 4 additions & 1 deletion clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1104,8 +1104,11 @@ def err_binding_multiple_ellipses : Error<
def note_previous_ellipsis : Note<
"previous binding pack specified here">;
def ext_cxx_binding_pack : ExtWarn<
"structured binding pack is incompatible with C++ standards before C++2c">,
"structured binding packs are a C++2c extension ">,
InGroup<CXX26>;
def warn_cxx23_compat_binding_pack : Warning<
"structured binding packs are incompatible with C++ standards before C++2c">,
InGroup<CXXPre26Compat>, DefaultIgnore;
def err_capture_default_first : Error<
"capture default must be first">;
def ext_decl_attrs_on_lambda : ExtWarn<
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7347,8 +7347,8 @@ void Parser::ParseDecompositionDeclarator(Declarator &D) {
SourceLocation EllipsisLoc;

if (Tok.is(tok::ellipsis)) {
if (!getLangOpts().CPlusPlus26)
Diag(Tok, diag::ext_cxx_binding_pack);
Diag(Tok, getLangOpts().CPlusPlus26 ? diag::warn_cxx23_compat_binding_pack
: diag::ext_cxx_binding_pack);
if (PrevEllipsisLoc.isValid()) {
Diag(Tok, diag::err_binding_multiple_ellipses);
Diag(PrevEllipsisLoc, diag::note_previous_ellipsis);
Expand Down
11 changes: 7 additions & 4 deletions clang/test/SemaCXX/cxx2c-binding-pack-nontemplate.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// RUN: %clang_cc1 -fsyntax-only -std=c++26 %s -verify=nontemplate
// RUN: %clang_cc1 -fsyntax-only %s -verify=nontemplate,compat
// RUN: %clang_cc1 -std=c++26 -fsyntax-only %s -verify=nontemplate
// RUN: %clang_cc1 -std=c++2c -verify=cxx26,nontemplate -fsyntax-only -Wpre-c++26-compat %s
// RUN: %clang_cc1 -std=c++23 -verify=cxx23,nontemplate -fsyntax-only -Wc++26-extensions %s

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

0 comments on commit 36f8029

Please sign in to comment.