From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 920BB3858D28 for ; Tue, 11 Oct 2022 20:00:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 920BB3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665518412; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yj6hALuKpEcpMx1J0+u4viFjSv7UV1eRZqOGTbrD4ns=; b=iss1/QlG5pFskChiDOKC9O5KejCJuVanBbwSjPRaLILhgoiwrrozCvZ4/F4bqCMaZ64MZq 1mzuf2fgKLyl+M5dyN6IgiinH6Q9by9aRG8EIg9atus5rwfG8w/ZB8X/viNneOWMrUJBPH bemvOit7AoxO06Nt2ciry5wRexnSMUY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-515-3yaEXJseM22mAy0jSrQSEA-1; Tue, 11 Oct 2022 16:00:11 -0400 X-MC-Unique: 3yaEXJseM22mAy0jSrQSEA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AECE185A583 for ; Tue, 11 Oct 2022 20:00:10 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.17.139]) by smtp.corp.redhat.com (Postfix) with ESMTP id 912A2C15BB3; Tue, 11 Oct 2022 20:00:10 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [PATCH] c++: ICE with VEC_INIT_EXPR and defarg [PR106925] Date: Tue, 11 Oct 2022 16:00:03 -0400 Message-Id: <20221011200003.695682-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/12? PR c++/106925 gcc/cp/ChangeLog: * except.cc (maybe_splice_retval_cleanup): Check current_function_decl. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/initlist-defarg3.C: New test. --- gcc/cp/except.cc | 3 +++ gcc/testsuite/g++.dg/cpp0x/initlist-defarg3.C | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-defarg3.C diff --git a/gcc/cp/except.cc b/gcc/cp/except.cc index b8a85ed0572..9f77289b9ca 100644 --- a/gcc/cp/except.cc +++ b/gcc/cp/except.cc @@ -1327,6 +1327,9 @@ maybe_splice_retval_cleanup (tree compound_stmt) && current_binding_level->level_chain->kind == sk_function_parms); if ((function_body || current_binding_level->kind == sk_try) + /* When we're processing a default argument, c_f_d may not have been + set. */ + && current_function_decl && !DECL_CONSTRUCTOR_P (current_function_decl) && !DECL_DESTRUCTOR_P (current_function_decl) && current_retval_sentinel) 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>()); base-commit: 23c3cbaed36f6d2f3a7a64f6ebda69329723514b -- 2.37.3