From patchwork Fri Apr 16 15:47:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1467089 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=nTQ2rQaz; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FMLFN0RClz9sVb for ; Sat, 17 Apr 2021 01:47:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AF5AE389246F; Fri, 16 Apr 2021 15:47:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AF5AE389246F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1618588050; bh=8jMaWKyEygUK5JKd1OxENDH/Y5xQW2Ohb2B8x7BZNX8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=nTQ2rQazpXQiiVO70UBtxFUKT97xADQeK+NORuYRmBYP3IdYp9uOgRCbFmv8UcM/+ wkzLrkUOye9KfXisrC3Z1AzeGzSCoNOjLf/xcx2OVTYFECaovuYyhv2wA6MAxB19kb oslX4GbG4hIpYKLaLeYYKS81+6V83e0YROCGIASs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id D0D073857C75 for ; Fri, 16 Apr 2021 15:47:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D0D073857C75 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-64-gy5bZfdJNZO3iSjsbUhrUw-1; Fri, 16 Apr 2021 11:47:25 -0400 X-MC-Unique: gy5bZfdJNZO3iSjsbUhrUw-1 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 11DE3106BAEB for ; Fri, 16 Apr 2021 15:47:25 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-115-183.ams2.redhat.com [10.36.115.183]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A5ACA5B4B2; Fri, 16 Apr 2021 15:47:24 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 13GFlMbU2040980 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 16 Apr 2021 17:47:22 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 13GFlLRI2040979; Fri, 16 Apr 2021 17:47:21 +0200 Date: Fri, 16 Apr 2021 17:47:21 +0200 To: Jason Merrill Subject: [committed] c++: Fix empty base stores in cxx_eval_store_expression [PR100111] Message-ID: <20210416154721.GG3748@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! In r11-6895 handling of empty bases has been fixed such that non-lval stores of empty classes are not added when the type of *valp doesn't match the type of the initializer, but as this testcase shows it is done only when *valp is non-NULL. If it is NULL, we still shouldn't add empty class constructors if the type of the constructor elt *valp points to doesn't match. Bootstrapped/regtested on x86_64-linux and i686-linux, tested also by Liu Hao on 10 branch, preapproved by Jason in the PR, committed to trunk. 2021-04-16 Jakub Jelinek PR c++/100111 * constexpr.c (cxx_eval_store_expression): Don't add CONSTRUCTORs for empty classes into *valp when types don't match even when *valp is NULL. * g++.dg/cpp0x/constexpr-100111.C: New test. Jakub --- gcc/cp/constexpr.c.jj 2021-04-08 17:19:12.235414181 +0200 +++ gcc/cp/constexpr.c 2021-04-16 11:06:27.138019389 +0200 @@ -5518,6 +5518,14 @@ cxx_eval_store_expression (const constex CONSTRUCTOR_NO_CLEARING (*valp) = CONSTRUCTOR_NO_CLEARING (init); } + else if (TREE_CODE (init) == CONSTRUCTOR + && !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (init), + type)) + { + /* See above on initialization of empty bases. */ + gcc_assert (is_empty_class (TREE_TYPE (init)) && !lval); + return init; + } else *valp = init; --- gcc/testsuite/g++.dg/cpp0x/constexpr-100111.C.jj 2021-04-16 11:33:20.193882609 +0200 +++ gcc/testsuite/g++.dg/cpp0x/constexpr-100111.C 2021-04-16 11:32:46.039266786 +0200 @@ -0,0 +1,7 @@ +// PR c++/100111 +// { dg-do compile { target c++11 } } +// { dg-options "-fno-elide-constructors" } + +struct A {}; +struct B : A { int b; constexpr B (A x) : A(x), b() {} }; +struct C { B c; constexpr C () : c({}) {} } d;