From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1734) id CE5FF3858403; Mon, 24 Oct 2022 18:07:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE5FF3858403 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666634823; bh=hmFsuIvGnsjz2DoxpW+Vr21dfAbUrn4v4ZFTWRERc0M=; h=From:To:Subject:Date:From; b=vnL85hm/tKt5jYDrhx/BMY15ZCHaCq1TJCWLHGwHgmFM2WP8aAbJSODNAvPtc6k8J SAIPb+L6EMQZyY95Q3MUdWMo0URdf1L59eUlGB2tmrbsemp+gqm0YEtswSNE6zGvdO xRW1saj5FAsjeFGQrjm+ND/QX0dCTYchpRxuiI/I= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marek Polacek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3462] c++: ICE with invalid structured bindings [PR107276] X-Act-Checkin: gcc X-Git-Author: Marek Polacek X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 65e3274e363cb2c6bfe6b5e648916eb7696f7e2f X-Git-Newrev: f7d8ccfda2d5c90dac97b1a3ede8b10391a3cc40 Message-Id: <20221024180703.CE5FF3858403@sourceware.org> Date: Mon, 24 Oct 2022 18:07:03 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f7d8ccfda2d5c90dac97b1a3ede8b10391a3cc40 commit r13-3462-gf7d8ccfda2d5c90dac97b1a3ede8b10391a3cc40 Author: Marek Polacek Date: Thu Oct 20 15:55:28 2022 -0400 c++: ICE with invalid structured bindings [PR107276] This test ICEs in C++23 because we reach the new code in do_auto_deduction: 30468 if (cxx_dialect >= cxx23 30469 && context == adc_return_type 30470 && (!AUTO_IS_DECLTYPE (auto_node) 30471 || !unparenthesized_id_or_class_member_access_p (init)) 30472 && (r = treat_lvalue_as_rvalue_p (maybe_undo_parenthesized_ref (init), 30473 /*return*/true))) where 'init' is "VIEW_CONVERT_EXPR<<<< error >>>>(y)", and then the move in treat_lvalue_as_rvalue_p returns error_mark_node whereupon set_implicit_rvalue_p crashes. I don't think such V_C_Es are useful so let's not create them. But that won't fix the ICE so I'm checking the return value of move. A structured bindings decl can have an error type, that is set in cp_finish_decomp: 8908 TREE_TYPE (first) = error_mark_node; therefore I think treat_lvalue_as_rvalue_p just needs to cope. PR c++/107276 gcc/cp/ChangeLog: * typeck.cc (treat_lvalue_as_rvalue_p): Check the return value of move. gcc/ChangeLog: * tree.cc (maybe_wrap_with_location): Don't create a location wrapper when the type is erroneous. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/decomp4.C: New test. Diff: --- gcc/cp/typeck.cc | 7 ++++++- gcc/testsuite/g++.dg/cpp2a/decomp4.C | 8 ++++++++ gcc/tree.cc | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index 530d260b1e8..ab6979bcc50 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -10729,7 +10729,12 @@ treat_lvalue_as_rvalue_p (tree expr, bool return_p) if (DECL_CONTEXT (retval) != current_function_decl) return NULL_TREE; if (return_p) - return set_implicit_rvalue_p (move (expr)); + { + expr = move (expr); + if (expr == error_mark_node) + return NULL_TREE; + return set_implicit_rvalue_p (expr); + } /* if the operand of a throw-expression is a (possibly parenthesized) id-expression that names an implicitly movable entity whose scope does not diff --git a/gcc/testsuite/g++.dg/cpp2a/decomp4.C b/gcc/testsuite/g++.dg/cpp2a/decomp4.C new file mode 100644 index 00000000000..d1b0c90ee26 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/decomp4.C @@ -0,0 +1,8 @@ +// PR c++/107276 +// { dg-do compile { target c++20 } } + +auto f(auto x) { + auto [y] = x; // { dg-error "cannot decompose" } + return y; +} +int i = f(0); diff --git a/gcc/tree.cc b/gcc/tree.cc index 81a6ceaf181..04603c8c902 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -14352,7 +14352,7 @@ maybe_wrap_with_location (tree expr, location_t loc) /* For now, don't add wrappers to exceptional tree nodes, to minimize any impact of the wrapper nodes. */ - if (EXCEPTIONAL_CLASS_P (expr)) + if (EXCEPTIONAL_CLASS_P (expr) || error_operand_p (expr)) return expr; /* Compiler-generated temporary variables don't need a wrapper. */