From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1734) id 125103858C55; Thu, 13 Oct 2022 15:06:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 125103858C55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665673574; bh=goLzfC/sbonyPaHtAuJ4SjAT31Pxhped987+nFMKslA=; h=From:To:Subject:Date:From; b=IeiVnKrxuKd7aeeUzGgDj+3yHOHus+QtL9S2BzR3GcNeaXAy1z9rYhmXEM5ia5HWT 9GIbgO37420WLd5/e3N7Ib5i20zk1oxvLca/vBUo/dQivFU4Sy/h+Q8nueLahR0vtV gCjmQoxilsYUJGQ0Olc7+N1W3IhZncez3SVpmIJs= 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-3277] c++: ICE with VEC_INIT_EXPR and defarg [PR106925] X-Act-Checkin: gcc X-Git-Author: Marek Polacek X-Git-Refname: refs/heads/trunk X-Git-Oldrev: e5139d18dfb8130876ea59178e8471fb1b34bb80 X-Git-Newrev: 3130e70dab1e64a7b014391fe941090d5f3b6b7d Message-Id: <20221013150614.125103858C55@sourceware.org> Date: Thu, 13 Oct 2022 15:06:14 +0000 (GMT) List-Id: https://gcc.gnu.org/g:3130e70dab1e64a7b014391fe941090d5f3b6b7d commit r13-3277-g3130e70dab1e64a7b014391fe941090d5f3b6b7d Author: Marek Polacek Date: Tue Oct 11 14:16:54 2022 -0400 c++: ICE with VEC_INIT_EXPR and defarg [PR106925] Since r12-8066, in cxx_eval_vec_init we perform expand_vec_init_expr while processing the default argument in this test. At this point start_preparsed_function hasn't yet set current_function_decl. expand_vec_init_expr then leads to maybe_splice_retval_cleanup which checks DECL_CONSTRUCTOR_P (current_function_decl) without checking that c_f_d is non-null first. It seems correct that c_f_d is null here, so it seems to me that maybe_splice_retval_cleanup should check c_f_d as in the following patch. PR c++/106925 gcc/cp/ChangeLog: * except.cc (maybe_splice_retval_cleanup): Check current_function_decl. Make the bool const. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/initlist-defarg3.C: New test. Diff: --- gcc/cp/except.cc | 7 +++++-- gcc/testsuite/g++.dg/cpp0x/initlist-defarg3.C | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gcc/cp/except.cc b/gcc/cp/except.cc index 703d1d566c9..2677a9b7678 100644 --- a/gcc/cp/except.cc +++ b/gcc/cp/except.cc @@ -1307,9 +1307,12 @@ maybe_splice_retval_cleanup (tree compound_stmt) { /* If we need a cleanup for the return value, add it in at the same level as pushdecl_outermost_localscope. And also in try blocks. */ - bool function_body + const bool function_body = (current_binding_level->level_chain - && current_binding_level->level_chain->kind == sk_function_parms); + && current_binding_level->level_chain->kind == sk_function_parms + /* When we're processing a default argument, c_f_d may not have been + set. */ + && current_function_decl); if ((function_body || current_binding_level->kind == sk_try) && !DECL_CONSTRUCTOR_P (current_function_decl) diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-defarg3.C b/gcc/testsuite/g++.dg/cpp0x/initlist-defarg3.C new file mode 100644 index 00000000000..5c3e886b306 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-defarg3.C @@ -0,0 +1,13 @@ +// PR c++/106925 +// { dg-do compile { target c++11 } } + +struct Foo; +template struct __array_traits { typedef Foo _Type[_Nm]; }; +template struct array { + typename __array_traits<_Nm>::_Type _M_elems; +}; +template struct MyVector { array data{}; }; +struct Foo { + float a{0}; +}; +void foo(MyVector<1> = MyVector<1>());