From patchwork Fri Apr 13 19:11:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 152385 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]) by ozlabs.org (Postfix) with SMTP id 83103B7012 for ; Sat, 14 Apr 2012 05:11:42 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1334949102; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=9+3Dun1 zexgNg/6B8wezcgAFZAw=; b=w6xVfHcPYP89B48lUfwRUnjmu4ZZK0m3ZfpQwLA Vy1Jk4ZfDPKQbSAFwcKDpZRsp5PoUsUu2rxokbENQjVmaemiopHv8t9mocp9Y3w9 Ab3QLZ7QxG4cwUIOOHrbkgkTrf4apiVbxweUNvdn4gESfqqlAaaOysCdN5DvSlu6 A3PU= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=EcEHimcq33dhFl6L9D2dlqUFQEpsNOWzAN2mZUCGwaIjy28wqr0KV2odZcFwbN sWt9ID3wEpVhG/BjS/UZDSUYLbP+aZZw8MbUssFsKRCHik8ivsT6NhJ8GgKNmP5L UoWyzbd22+Xuy1cGJCj8dIXjfwIgEzvsCBsIEGMKcQqRk=; Received: (qmail 10404 invoked by alias); 13 Apr 2012 19:11:38 -0000 Received: (qmail 10392 invoked by uid 22791); 13 Apr 2012 19:11:37 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 13 Apr 2012 19:11:24 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3DJBOUu027317 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 13 Apr 2012 15:11:24 -0400 Received: from [10.3.113.125] (ovpn-113-125.phx2.redhat.com [10.3.113.125]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q3DJBNR1016085 for ; Fri, 13 Apr 2012 15:11:23 -0400 Message-ID: <4F887A5B.70408@redhat.com> Date: Fri, 13 Apr 2012 15:11:23 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20120329 Thunderbird/11.0.1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/52915 (accepts-invalid anonymous union in C++11 mode) 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 C++11 extends unions so that a member can have a non-trivial default constructor, but the union then has a deleted constructor unless the user defines one. As a result, we can't assume that an anonymous union has a trivial default constructor anymore. Tested x86_64-pc-linux-gnu, applying to trunk. commit 761b558950409d024fd509228b1a3e04fcefb38a Author: Jason Merrill Date: Thu Apr 12 18:10:48 2012 -0400 PR c++/52915 * decl2.c (finish_anon_union): Use cp_finish_decl. * error.c (dump_function_name): Avoid showing anonymous "name". diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index b048ac7..212feea 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1456,12 +1456,7 @@ finish_anon_union (tree anon_union_decl) } pushdecl (anon_union_decl); - if (building_stmt_list_p () - && at_function_scope_p ()) - add_decl_expr (anon_union_decl); - else if (!processing_template_decl) - rest_of_decl_compilation (anon_union_decl, - toplevel_bindings_p (), at_eof); + cp_finish_decl (anon_union_decl, NULL_TREE, false, NULL_TREE, 0); } /* Auxiliary functions to make type signatures for diff --git a/gcc/cp/error.c b/gcc/cp/error.c index ee8f0e0..77eb306 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -1556,6 +1556,8 @@ dump_function_name (tree t, int flags) { if (LAMBDA_TYPE_P (DECL_CONTEXT (t))) name = get_identifier (""); + else if (TYPE_ANONYMOUS_P (DECL_CONTEXT (t))) + name = get_identifier (""); else name = constructor_name (DECL_CONTEXT (t)); } diff --git a/gcc/testsuite/g++.dg/other/anon-union2.C b/gcc/testsuite/g++.dg/other/anon-union2.C new file mode 100644 index 0000000..31bb74f --- /dev/null +++ b/gcc/testsuite/g++.dg/other/anon-union2.C @@ -0,0 +1,10 @@ +// PR c++/52915 + +struct S { + int val; + S(int v) : val(v) {} +}; + +void f() { + union { S a; }; // { dg-error "constructor|no match" } +}