From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 929BA3857C45; Sun, 24 Sep 2023 18:42:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 929BA3857C45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695580974; bh=odysQw/cvUcAvI/FMEZT5ezjqwbH3uDLkvAzHZW59IE=; h=From:To:Subject:Date:From; b=TCpKiLCslWZ2v7adajzK2vBNEzIh/nSFLwsF7dhSjdW+ofDj5h6TeinOafkgFcHe+ ThE/opcckoV7rKwKyFjCsd+oWnpy0LQusC63bAZ6dEPVEHOzccnigELbcVgMnybDv3 STyrQTq7nEVtO5hhZTWpGltJ1dO6iYnrh8Udkzo8= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-7837] c++: missing SFINAE in grok_array_decl [PR111493] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: 59f5786c20a42be13ac6fec567ffe840045012ad X-Git-Newrev: 40d2dec34b58c3c31b1c731049a914204ec252c3 Message-Id: <20230924184254.929BA3857C45@sourceware.org> Date: Sun, 24 Sep 2023 18:42:54 +0000 (GMT) List-Id: https://gcc.gnu.org/g:40d2dec34b58c3c31b1c731049a914204ec252c3 commit r13-7837-g40d2dec34b58c3c31b1c731049a914204ec252c3 Author: Patrick Palka Date: Fri Sep 22 06:27:48 2023 -0400 c++: missing SFINAE in grok_array_decl [PR111493] We should guard both the diagnostic and backward compatibilty fallback code with tf_error, so that in a SFINAE context we don't issue any diagnostics and correctly treat ill-formed C++23 multidimensional subscript operator expressions as such. PR c++/111493 gcc/cp/ChangeLog: * decl2.cc (grok_array_decl): Guard diagnostic and backward compatibility fallback code paths with tf_error. gcc/testsuite/ChangeLog: * g++.dg/cpp23/subscript15.C: New test. (cherry picked from commit 1fea14def849dd38b098b0e2d54e64801f9c1f43) Diff: --- gcc/cp/decl2.cc | 15 ++++++++++++--- gcc/testsuite/g++.dg/cpp23/subscript15.C | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 1dd3c2b13bc..36e1f2ce300 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -459,7 +459,10 @@ grok_array_decl (location_t loc, tree array_expr, tree index_exp, { expr = build_op_subscript (loc, array_expr, index_exp_list, &overload, complain & tf_decltype); - if (expr == error_mark_node) + if (expr == error_mark_node + /* Don't do the backward compatibility fallback in a SFINAE + context. */ + && (complain & tf_error)) { tree idx = build_x_compound_expr_from_vec (*index_exp_list, NULL, tf_none); @@ -510,6 +513,11 @@ grok_array_decl (location_t loc, tree array_expr, tree index_exp, if (index_exp == NULL_TREE) { + if (!(complain & tf_error)) + /* Don't do the backward compatibility fallback in a SFINAE + context. */ + return error_mark_node; + if ((*index_exp_list)->is_empty ()) { error_at (loc, "built-in subscript operator without expression " @@ -561,8 +569,9 @@ grok_array_decl (location_t loc, tree array_expr, tree index_exp, swapped = true, array_expr = p2, index_exp = i1; else { - error_at (loc, "invalid types %<%T[%T]%> for array subscript", - type, TREE_TYPE (index_exp)); + if (complain & tf_error) + error_at (loc, "invalid types %<%T[%T]%> for array subscript", + type, TREE_TYPE (index_exp)); return error_mark_node; } diff --git a/gcc/testsuite/g++.dg/cpp23/subscript15.C b/gcc/testsuite/g++.dg/cpp23/subscript15.C new file mode 100644 index 00000000000..fece96be96b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/subscript15.C @@ -0,0 +1,25 @@ +// PR c++/111493 +// { dg-do compile { target c++23 } } + +template +concept CartesianIndexable = requires(T t, Ts... ts) { t[ts...]; }; + +static_assert(!CartesianIndexable); +static_assert(!CartesianIndexable); +static_assert(!CartesianIndexable); + +static_assert(!CartesianIndexable); +static_assert(CartesianIndexable); +static_assert(!CartesianIndexable); +static_assert(!CartesianIndexable); + +template +struct A { + void operator[](Ts...); +}; + +static_assert(!CartesianIndexable, int>); +static_assert(CartesianIndexable, int>); +static_assert(!CartesianIndexable>); +static_assert(!CartesianIndexable, int, int>); +static_assert(CartesianIndexable, int, int>);