From patchwork Tue Feb 25 21:15:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 324098 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 958692C00AD for ; Wed, 26 Feb 2014 08:15:41 +1100 (EST) 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=ew54bPzYJcwu+E8N5WYZTOpRPvq4Q3cXLy7jZFSh9iESxy jj+eElxDjPf5K//+DoivwLyHjXlQScr4OGow58lttLYy0+HOIS4/eGgGLgjDkxBB 7P0f4s0iYCEv3O4WsVh67J3+FohzwsF/v3Yj5ozTYlzNPCc8qIXsxLgfztP2s= 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=TOXMKoOtFCR9fybZUCxmawo2Ovk=; b=R465jmubzpdXVRdUJxUl dFKOQB03T49yX7V/jijUnxWCDaEtHCDDpBjW8bDznmeh1jaspc4XEv8/tVT6aMds 1gUnShS/xzDjM0K2xQe74JoGQ0HSa3PY537KzXfctc2stiPqH2UzjSW7BPQbt21a LEOUjQ3fieXLNiwkFfyE36M= Received: (qmail 9297 invoked by alias); 25 Feb 2014 21:15:34 -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 9287 invoked by uid 89); 25 Feb 2014 21:15:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS 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 ESMTP; Tue, 25 Feb 2014 21:15:31 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1PLFTRR009213 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 25 Feb 2014 16:15:29 -0500 Received: from [10.3.113.140] (ovpn-113-140.phx2.redhat.com [10.3.113.140]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s1PLFSs9013717 for ; Tue, 25 Feb 2014 16:15:28 -0500 Message-ID: <530D07F0.3050205@redhat.com> Date: Tue, 25 Feb 2014 16:15:28 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/55877 (names for linkage purposes) My earlier patch didn't go far enough; when we apply a name for linkage purposes and fix up the visibility of the type, we also need to fix up the visibility and names of any members and implementation bits. At first I thought we would need to deal with static data members as well as functions, but it turns out that an unnamed class can't have static data members. So the second patch enforces that better. Tested x86_64-pc-linux-gnu, applying to trunk. commit 8bf3ffa515e08c9fb815e6663c16acd39af9056a Author: Jason Merrill Date: Sun Feb 9 19:31:28 2014 -0500 * decl2.c (finish_static_data_member_decl): Diagnose static data member in unnamed class. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index e861e4d..f61dc9d 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -2851,7 +2851,9 @@ finish_struct_anon_r (tree field, bool complain) if (TREE_CODE (elt) != FIELD_DECL) { - if (complain) + /* We already complained about static data members in + finish_static_data_member_decl. */ + if (complain && TREE_CODE (elt) != VAR_DECL) { if (is_union) permerror (input_location, diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 35707a0..f512541 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -802,6 +802,17 @@ finish_static_data_member_decl (tree decl, && !DECL_TEMPLATE_INSTANTIATION (decl)) permerror (input_location, "local class %q#T shall not have static data member %q#D", current_class_type, decl); + else + for (tree t = current_class_type; TYPE_P (t); + t = CP_TYPE_CONTEXT (t)) + if (TYPE_ANONYMOUS_P (t)) + { + if (permerror (DECL_SOURCE_LOCATION (decl), + "static data member %qD in unnamed class", decl)) + inform (DECL_SOURCE_LOCATION (TYPE_NAME (t)), + "unnamed class defined here"); + break; + } DECL_IN_AGGR_P (decl) = 1; diff --git a/gcc/testsuite/g++.dg/ext/anon-struct5.C b/gcc/testsuite/g++.dg/ext/anon-struct5.C index 8b697cc..ec02225 100644 --- a/gcc/testsuite/g++.dg/ext/anon-struct5.C +++ b/gcc/testsuite/g++.dg/ext/anon-struct5.C @@ -2,12 +2,12 @@ struct A { - struct { static int i; }; // { dg-error "prohibits anonymous structs|an anonymous struct" } + struct { static int i; }; // { dg-error "prohibits anonymous structs|an anonymous struct|unnamed class" } void foo() { i; } }; struct B { - union { static int i; }; // { dg-error "an anonymous union|member of a union" } + union { static int i; }; // { dg-error "an anonymous union|member of a union|unnamed class" } void foo() { i; } }; diff --git a/gcc/testsuite/g++.dg/ext/anon-struct6.C b/gcc/testsuite/g++.dg/ext/anon-struct6.C index 11a7bbd..66d4b32 100644 --- a/gcc/testsuite/g++.dg/ext/anon-struct6.C +++ b/gcc/testsuite/g++.dg/ext/anon-struct6.C @@ -4,7 +4,7 @@ struct A { struct { // { dg-error "anonymous struct cannot have function members" } - struct { static int i; }; // { dg-error "prohibits anonymous structs|non-static data members" } + struct { static int i; }; // { dg-error "prohibits anonymous structs|non-static data members|unnamed class" } void foo() { i; } }; // { dg-error "prohibits anonymous structs" } }; diff --git a/gcc/testsuite/g++.dg/parse/unnamed1.C b/gcc/testsuite/g++.dg/parse/unnamed1.C new file mode 100644 index 0000000..f5972f1 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/unnamed1.C @@ -0,0 +1,6 @@ +// 9.4.2/4: Unnamed classes and classes contained directly or indirectly +// within unnamed classes shall not contain static data members. + +typedef struct { // { dg-message "unnamed" } + static int i; // { dg-error "static data member" } +} A;