From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id B4BF93857437; Thu, 30 Mar 2023 21:09:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B4BF93857437 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680210552; bh=HptWZAqbDiyYy0lJV9litxGMuflalcSxePEWNz9VqBk=; h=From:To:Subject:Date:From; b=YDWi4H93fS3ki9z7H0efS2szKulncAuM13ibT3zvskynVg6iUsIXdoEYXr4Fj4vZZ mxavpUyedBOiKAdvndu5y3m57qDKi1HEOXpQ5zPsT2YuCFXZ9vae8TfNI2BS7bsL5D QbIn1Bz2Fc7Qb84cIAnUOyuoEU9tOC+52DMRdrCk= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6946] c++: Fix up ICE in build_min_non_dep_op_overload [PR109319] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 429a7a88438cc80e7c58d9f63d44838089899b12 X-Git-Newrev: c016887c91a79d67b6a3c7e19b9219f5ab1e2a4d Message-Id: <20230330210912.B4BF93857437@sourceware.org> Date: Thu, 30 Mar 2023 21:09:12 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c016887c91a79d67b6a3c7e19b9219f5ab1e2a4d commit r13-6946-gc016887c91a79d67b6a3c7e19b9219f5ab1e2a4d Author: Jakub Jelinek Date: Thu Mar 30 23:08:25 2023 +0200 c++: Fix up ICE in build_min_non_dep_op_overload [PR109319] The following testcase ICEs, because grok_array_decl during processing_template_decl handling of a non-dependent subscript emits a -Wcomma-subscript pedwarn, we decide to pass to the single index argument the index expressions as if it was wrapped with () around it, but then when preparing it for later instantiation we don't actually take that into account and ICE on a mismatch of number of index arguments (the overload expects a single index, testcase has two index expressions in this case). For non-dependent subscript which are builtin subscripts we also emit the same pedwarn and don't ICE, but emit the same pedwarn again whenever we instantiate it, which is also IMHO undesirable, it is enough to warn once during parsing the template. The following patch fixes it by turning even the original index expressions (those which didn't go through make_args_non_dependent) into a single index using comma expression(s). 2023-03-30 Jakub Jelinek PR c++/109319 * decl2.cc (grok_array_decl): After emitting a pedwarn for -Wcomma-subscript, if processing_template_decl set orig_index_exp to compound expr from orig_index_exp_list. * g++.dg/cpp23/subscript14.C: New test. Diff: --- gcc/cp/decl2.cc | 31 +++++++++++++++++++---- gcc/testsuite/g++.dg/cpp23/subscript14.C | 42 ++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 5 deletions(-) diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 201f1e6b6b9..2b195e99997 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -474,11 +474,23 @@ grok_array_decl (location_t loc, tree array_expr, tree index_exp, &overload, complain); } else - /* If it would be valid albeit deprecated expression in C++20, - just pedwarn on it and treat it as if wrapped in (). */ - pedwarn (loc, OPT_Wcomma_subscript, - "top-level comma expression in array subscript " - "changed meaning in C++23"); + { + /* If it would be valid albeit deprecated expression in + C++20, just pedwarn on it and treat it as if wrapped + in (). */ + pedwarn (loc, OPT_Wcomma_subscript, + "top-level comma expression in array subscript " + "changed meaning in C++23"); + if (processing_template_decl) + { + orig_index_exp + = build_x_compound_expr_from_vec (orig_index_exp_list, + NULL, complain); + if (orig_index_exp == error_mark_node) + expr = error_mark_node; + release_tree_vector (orig_index_exp_list); + } + } } } } @@ -519,6 +531,15 @@ grok_array_decl (location_t loc, tree array_expr, tree index_exp, return error_mark_node; } index_exp = idx; + if (processing_template_decl) + { + orig_index_exp + = build_x_compound_expr_from_vec (orig_index_exp_list, + NULL, complain); + release_tree_vector (orig_index_exp_list); + if (orig_index_exp == error_mark_node) + return error_mark_node; + } } if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE) diff --git a/gcc/testsuite/g++.dg/cpp23/subscript14.C b/gcc/testsuite/g++.dg/cpp23/subscript14.C new file mode 100644 index 00000000000..042799c6aba --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/subscript14.C @@ -0,0 +1,42 @@ +// PR c++/109319 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +struct A { static int &operator[] (int x) { static int a[2]; return a[x]; } }; // { dg-warning "may be a static member function only with" "" { target c++20_down } } +struct B { int &operator[] (int x) { static int b[2]; return b[x]; } }; +int c[2]; + +template +int +foo () +{ + A a; + ++a[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } } + B b; // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 } + ++b[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } } + // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 } + ++c[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } } + T d; // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 } + ++d[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } } + U e; // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 } + ++e[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } } + extern V f[2]; // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 } + ++f[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } } + return 0; // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 } +} + +int f[2]; + +int +main () +{ + A a; + ++a[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } } + B b; // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 } + ++b[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } } + // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 } + ++c[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } } + foo (); // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 } + if (a.operator[] (1) != 3 || b.operator[] (1) != 3 || c[1] != 2 || f[1] != 1) + __builtin_abort (); +}