From patchwork Tue Jun 9 14:12:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 482241 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 8DFB0140757 for ; Wed, 10 Jun 2015 00:12:56 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=vzpO214C; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=HcaFc7kaxPEZ30gAKkAO4tx937YGy+zqFAKk2iOtvjwqJH WPcd1xIsMU91hIhEuvs+k02kxCrh+E2lWZfZTjEyyxE9FwzRhigUvopOKvXArig6 VNzlSlETyaQYGIreR6wmPnAJ9VwoU1WEyOD7cwU/ygVgcAFtjrEWb+8+M3vu8= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=7FTf10UXZRLyg+8OalYtwFsGHN4=; b=vzpO214CCrbwVBTSu3P8 1IIFZfOuCB12CuN70wuCfa/utAzU6gtHHYuZCDLNaAHcjW0XzwIZm/mRxzsebugt myWJ0HEQARCKe0iBhU1vPxBxtMpdjW53A79XTQSYj39D8LgU0ailNMxmAQ9NNKtQ 8M1fswXn/qYgCY9LDeZOyPQ= Received: (qmail 4403 invoked by alias); 9 Jun 2015 14:12:38 -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 4308 invoked by uid 89); 9 Jun 2015 14:12:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 09 Jun 2015 14:12:35 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 894868E50C for ; Tue, 9 Jun 2015 14:12:33 +0000 (UTC) Received: from [10.10.116.44] ([10.10.116.44]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t59ECWb6028990 for ; Tue, 9 Jun 2015 10:12:33 -0400 Message-ID: <5576F44D.6040409@redhat.com> Date: Tue, 09 Jun 2015 10:12:29 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/66383 (aggregate NSDMI issue) In this testcase we end up with the initializer for the A subobject referring to the address of the B PLACEHOLDER_EXPR, which wasn't getting replaced properly because when we see the A TARGET_EXPR we stopped looking for more PLACEHOLDER_EXPRs. Instead, we need to keep looking, and learn how to handle placeholders for enclosing objects as well as the innermost one. Tested x86_64-pc-linux-gnu, applying to trunk and 5. commit 26b958fac8f8c42ab0158583c6a362caf4a9ab73 Author: Jason Merrill Date: Fri Jun 5 17:07:23 2015 -0400 PR c++/66383 * tree.c (replace_placeholders_r): Handle placeholders for an outer object. * typeck2.c (store_init_value): Only replace_placeholders for objects of class type. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 3c4b527..3553d7c 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -2552,15 +2552,15 @@ replace_placeholders_r (tree* t, int* walk_subtrees, void* data_) switch (TREE_CODE (*t)) { case PLACEHOLDER_EXPR: - gcc_assert (same_type_ignoring_top_level_qualifiers_p - (TREE_TYPE (*t), TREE_TYPE (obj))); - *t = obj; - *walk_subtrees = false; - break; - - case TARGET_EXPR: - /* Don't mess with placeholders in an unrelated object. */ - *walk_subtrees = false; + { + tree x = obj; + for (; !(same_type_ignoring_top_level_qualifiers_p + (TREE_TYPE (*t), TREE_TYPE (x))); + x = TREE_OPERAND (x, 0)) + gcc_assert (TREE_CODE (x) == COMPONENT_REF); + *t = x; + *walk_subtrees = false; + } break; case CONSTRUCTOR: diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index affa265..22a5580 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -836,7 +836,7 @@ store_init_value (tree decl, tree init, vec** cleanups, int flags) TREE_CONSTANT (decl) = const_init && decl_maybe_constant_var_p (decl); } - if (cxx_dialect >= cxx14) + if (cxx_dialect >= cxx14 && CLASS_TYPE_P (strip_array_types (type))) /* Handle aggregate NSDMI in non-constant initializers, too. */ value = replace_placeholders (value, decl); diff --git a/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr3.C b/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr3.C new file mode 100644 index 0000000..185ea10 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr3.C @@ -0,0 +1,43 @@ +// PR c++/66383 +// { dg-do compile { target c++11 } } + +namespace N1 { + struct B; + + struct A + { + B* b; + A(B* b); + }; + + struct B + { + A a{ this }; + }; + + A::A(B* b): b{ b } {} + + void foo() + { + auto b = B{}; + } +} + +namespace N2 { + struct B; + + struct A + { + B* b; + }; + + struct B + { + A a{ this }; + }; + + void foo() + { + auto b = B{}; + } +}