From patchwork Tue Feb 25 23:07:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1244572 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-520124-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=KSvy5oUm; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RJ814c9U; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48Rvjr0TgHz9sPR for ; Wed, 26 Feb 2020 10:08:14 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=J9i jbOzJ6zEH+GxaB2w7Rhgd095Mf1scze3CplcnkkFBZz2wGchJWm4W8ZJzxneJa0G 6hqY+9wAAlCsm5HgSuN7DnjoB5WtBoa7E99aPiM2+PkHiWw4vd/oJHpXz3do76q5 VMhkE2sAHMLLK/p82OI5/g0lyWkUMFJerXoJ8y5c= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; s=default; bh=NYF6I4KUY lGaIhYBmgoTxCNLdSA=; b=KSvy5oUmV+lbabgZUeFapNvOL3uM+XNUsVlhAh1fq 4Ty4mCCDlFuGHeakCuR3UE4uEhlF6SIzWWndUFvMWFkBNQ76+EkZgOl27tkG6cVN wfa1AzLKRkz3ewWxsivC74FL0N9vfHS1rI7LSiard+SUzky+qTGj40kon1Zk92gf Gs= Received: (qmail 3396 invoked by alias); 25 Feb 2020 23:08:06 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 3383 invoked by uid 89); 25 Feb 2020 23:08:05 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-8.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=UD:C.jj X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Feb 2020 23:08:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582672082; 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: content-transfer-encoding:content-transfer-encoding; bh=Gsd1ZG5GizYrvTbuxLM2Br+6JlJAFDHpKDBXwkCBVYU=; b=RJ814c9UVPX/xu3RD7S14Z/d36i9nT/kEM55fEq8cciG1hshC+P0ZaxuD2coXq1w6DV7k/ S4OTuVI1aQh4SS808OZ3jnx69AEszC8qec4wSJOl7X+nZJ1UmxrH1/dKzJop8/THz+CexT oo+g9KlKrR4iisAhZyvlQIc/G6662+s= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-255-wieEIKSaOw-UA7N69T080A-1; Tue, 25 Feb 2020 18:08:00 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E532F477 for ; Tue, 25 Feb 2020 23:07:59 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-21.ams2.redhat.com [10.36.116.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 764F08C066; Tue, 25 Feb 2020 23:07:59 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id 01PN7vkb009876; Wed, 26 Feb 2020 00:07:57 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 01PN7uXA009875; Wed, 26 Feb 2020 00:07:56 +0100 Date: Wed, 26 Feb 2020 00:07:55 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix rejects-valid bug in cxx_eval_outermost_constant_expr [PR93905] Message-ID: <20200225230755.GO2155@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-IsSubscribed: yes Hi! The following testcase is rejected in 8.3, but was accepted in 8.2 and is in 9.x. This started with my PR87934 * constexpr.c (cxx_eval_constant_expression) : Do re-process TREE_CONSTANT CONSTRUCTORs if they aren't reduced constant expressions. backport, where the NSDMI CONSTRUCTOR that contains CONST_DECLs is now constexpr evaluated so that it doesn't contain them. The difference from 9.x is that 9.x doesn't call get_target_expr if we got a CONSTRUCTOR for a class type for something that has been originally a CONSTRUCTOR too. This patch cherry-picks just that hunk of the r9-3835 change. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for 8.4? Is the testcase alone ok for trunk/9.3? 2020-02-25 Jakub Jelinek PR c++/93905 Backported from mainline 2018-11-04 Jason Merrill * constexpr.c (cxx_eval_outermost_constant_expr): Don't wrap a CONSTRUCTOR if one was passed in. * g++.dg/cpp0x/pr93905.C: New test. Jakub --- gcc/cp/constexpr.c.jj 2020-02-25 14:04:47.912615737 +0100 +++ gcc/cp/constexpr.c 2020-02-25 21:05:02.537781661 +0100 @@ -4977,15 +4977,13 @@ cxx_eval_outermost_constant_expr (tree t if (TREE_CODE (t) == TARGET_EXPR && TARGET_EXPR_INITIAL (t) == r) return t; - else + else if (TREE_CODE (t) != CONSTRUCTOR) { r = get_target_expr (r); TREE_CONSTANT (r) = true; - return r; } } - else - return r; + return r; } /* Returns true if T is a valid subexpression of a constant expression, --- gcc/testsuite/g++.dg/cpp0x/pr93905.C.jj 2020-02-25 21:03:51.976820018 +0100 +++ gcc/testsuite/g++.dg/cpp0x/pr93905.C 2020-02-25 21:03:28.281168717 +0100 @@ -0,0 +1,18 @@ +// PR c++/93905 +// { dg-do compile { target c++11 } } + +enum class E { VALUE }; + +struct B { + E e{E::VALUE}; +protected: + ~B () = default; +}; + +struct D : B {}; + +int +main () +{ + D d{}; +}