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.133.124]) by sourceware.org (Postfix) with ESMTPS id D2613383D82A for ; Wed, 1 Jun 2022 22:45:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D2613383D82A Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-550-SNjQAOgMMUyEA9lJnC4p5w-1; Wed, 01 Jun 2022 18:45:43 -0400 X-MC-Unique: SNjQAOgMMUyEA9lJnC4p5w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D8A6129AB41A for ; Wed, 1 Jun 2022 22:45:42 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.17.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB8EF40CFD0A; Wed, 1 Jun 2022 22:45:42 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: ICE with template NEW_EXPR [PR105803] Date: Wed, 1 Jun 2022 18:45:36 -0400 Message-Id: <20220601224536.1553412-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 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=-13.1 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Jun 2022 22:45:46 -0000 Here we ICE because value_dependent_expression_p gets a NEW_EXPR whose operand is a type, and we go to the default case which just calls v_d_e_p on each operand of the NEW_EXPR. Since one of them is a type, we crash on the new assert in t_d_e_p. t_d_e_p has code to handle {,VEC_}NEW_EXPR, which at this point was already performed, so I think we can handle these two codes specifically and skip the second operand, which is always going to be a type. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? PR c++/105803 gcc/cp/ChangeLog: * pt.cc (value_dependent_expression_p): Handle {,VEC_}NEW_EXPR in the switch. gcc/testsuite/ChangeLog: * g++.dg/template/new13.C: New test. --- gcc/cp/pt.cc | 8 ++++++++ gcc/testsuite/g++.dg/template/new13.C | 11 +++++++++++ 2 files changed, 19 insertions(+) create mode 100644 gcc/testsuite/g++.dg/template/new13.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 6de8e496859..836861e1039 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -27643,6 +27643,14 @@ value_dependent_expression_p (tree expression) under instantiate_non_dependent_expr; it can't be constant. */ return true; + case NEW_EXPR: + case VEC_NEW_EXPR: + /* The second operand is a type, which type_dependent_expression_p + (and therefore value_dependent_expression_p) doesn't want to see. */ + return (value_dependent_expression_p (TREE_OPERAND (expression, 0)) + || value_dependent_expression_p (TREE_OPERAND (expression, 2)) + || value_dependent_expression_p (TREE_OPERAND (expression, 3))); + default: /* A constant expression is value-dependent if any subexpression is value-dependent. */ diff --git a/gcc/testsuite/g++.dg/template/new13.C b/gcc/testsuite/g++.dg/template/new13.C new file mode 100644 index 00000000000..3168374b26d --- /dev/null +++ b/gcc/testsuite/g++.dg/template/new13.C @@ -0,0 +1,11 @@ +// PR c++/105803 +// { dg-do compile } +// { dg-additional-options "-fchecking=2" } + +namespace std { +template class shared_ptr; +} +struct S {}; +template void build_matrices() { + std::shared_ptr(new S); +} base-commit: 2d546ff69455f7deadab65309de89d19380a8864 -- 2.36.1