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 812C43858D33 for ; Wed, 22 Feb 2023 09:06:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 812C43858D33 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=1677056803; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=brI0xagwqRZbZe3c+oYHJ7/JyLNzegNo0G3QtRSQkmU=; b=DLh43/In0EiHl6TcfnBYaZOXLV9XaVv5JU1DJRqvS94JwSPSyeA5RcveAMPzG7lYgiyLE9 KyUS4w9gmWiM4tsM+66GablggwOW4T93V3ZbBqXFQKxdIvKzjRJRbNcZF/aNsJge2NrcWE cj2Oypjf+HW608xdYqDsb0ZR+yZoNZQ= 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-403-BmaNIhJVOw69dvvC1hj2Jw-1; Wed, 22 Feb 2023 04:06:32 -0500 X-MC-Unique: BmaNIhJVOw69dvvC1hj2Jw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EE4C638041DB for ; Wed, 22 Feb 2023 09:06:31 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.62]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B27A41415113; Wed, 22 Feb 2023 09:06:31 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 31M96TKN4178251 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 22 Feb 2023 10:06:29 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 31M96TrA4178250; Wed, 22 Feb 2023 10:06:29 +0100 Date: Wed, 22 Feb 2023 10:06:28 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Don't recurse on DECL_INITIAL for DECL_EXPR on non-VAR_DECLs [PR108606] Message-ID: Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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: Hi! The r13-2965-g73d9b0e5947e16 change changed the line touched in this patch from return RECUR (tmp, want_rval); to return RECUR (DECL_INITIAL (tmp), want_rval); This is on DECL_EXPR handling code, where tmp can be lots of different trees and DECL_INITIAL unfortunately also means different things on different trees. It is the initializer on VAR_DECL, DECL_ARG_TYPE on PARM_DECLs (though those are unlikely to have DECL_EXPRs), for FUNCTION_DECLs the body, ..., USING_DECL_DECLS on USING_DECLs and DECL_FRIENDLIST on TYPE_DECLs. The testcase below ICEs because we have a DECL_EXPR for TYPE_DECL which has non-NULL DECL_FRIENDLIST and we certainly can't recurse on the friend list. The following patch is a conditional partial reversion of r13-2965, it will recurse on DECL_INITIAL only for VAR_DECLs and for anything else keep previous behavior. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-02-22 Jakub Jelinek PR c++/108606 * constexpr.cc (potential_constant_expression_1) : Only recurse on DECL_INITIAL (tmp) if tmp is a VAR_DECL, otherwise recurse on tmp. * g++.dg/cpp1y/pr108606.C: New test. --- gcc/cp/constexpr.cc.jj 2023-02-20 22:06:36.000000000 +0100 +++ gcc/cp/constexpr.cc 2023-02-21 14:40:39.366910531 +0100 @@ -9699,7 +9699,9 @@ potential_constant_expression_1 (tree t, (tmp, /*constexpr_context_p=*/true, flags)) return false; } - return RECUR (DECL_INITIAL (tmp), want_rval); + if (VAR_P (tmp)) + return RECUR (DECL_INITIAL (tmp), want_rval); + return RECUR (tmp, want_rval); case TRY_FINALLY_EXPR: return (RECUR (TREE_OPERAND (t, 0), want_rval) --- gcc/testsuite/g++.dg/cpp1y/pr108606.C.jj 2023-02-21 14:44:41.292380973 +0100 +++ gcc/testsuite/g++.dg/cpp1y/pr108606.C 2023-02-21 14:44:15.622755459 +0100 @@ -0,0 +1,11 @@ +// PR c++/108606 +// { dg-do compile { target c++14 } } + +template +void bar (T) {} + +void +foo () +{ + bar ([&] (auto x) { class C { friend void baz (); }; }); +} Jakub