From patchwork Thu Jun 23 16:49:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 101654 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 D015CB6F91 for ; Fri, 24 Jun 2011 02:49:22 +1000 (EST) Received: (qmail 10970 invoked by alias); 23 Jun 2011 16:49:20 -0000 Received: (qmail 10955 invoked by uid 22791); 23 Jun 2011 16:49:19 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from smtp207.alice.it (HELO smtp207.alice.it) (82.57.200.103) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 23 Jun 2011 16:49:06 +0000 Received: from [192.168.1.4] (79.52.194.95) by smtp207.alice.it (8.5.124.08) id 4DFA189A00B34BDC; Thu, 23 Jun 2011 18:49:03 +0200 Message-ID: <4E036EAE.5010507@oracle.com> Date: Thu, 23 Jun 2011 18:49:50 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110414 SUSE/3.1.10 Thunderbird/3.1.10 MIME-Version: 1.0 To: Jason Merrill CC: "gcc-patches@gcc.gnu.org" Subject: Re: [C++ Patch] PR 44625 References: <4E031E9C.8090502@oracle.com> <4E0352EF.6000007@redhat.com> <4E035C0C.2070407@oracle.com> <4E035FF6.4050209@redhat.com> <4E03613B.2020302@oracle.com> <4E036350.7010700@redhat.com> <4E036459.2090903@redhat.com> In-Reply-To: <4E036459.2090903@redhat.com> X-IsSubscribed: yes 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 On 06/23/2011 06:05 PM, Jason Merrill wrote: > So we should be able to just reject nested anonymous aggregates and > not worry about how to make them work. The below appears to work pretty well, regtests fine. I had to tweak the existing error17.C, we don't emit anymore the warning about no members in the nested anonymous struct, because we bail out early. Doesn't seem a serious issue to me... Ok? Paolo. ////////////////////// /cp 2011-06-23 Paolo Carlini PR c++/44625 * decl2.c (build_anon_union_vars): Early return error_mark_node for a nested anonymous struct. /testsuite 2011-06-23 Paolo Carlini PR c++/44625 * g++.dg/template/crash107.C: New. * g++.dg/template/error17.C: Adjust. Index: testsuite/g++.dg/template/error17.C =================================================================== --- testsuite/g++.dg/template/error17.C (revision 175330) +++ testsuite/g++.dg/template/error17.C (working copy) @@ -6,5 +6,4 @@ foo() { union { struct { }; }; // { dg-error "prohibits anonymous struct" "anon" } // { dg-error "not inside" "not inside" { target *-*-* } 7 } - // { dg-warning "no members" "no members" { target *-*-* } 7 } } Index: testsuite/g++.dg/template/crash107.C =================================================================== --- testsuite/g++.dg/template/crash107.C (revision 0) +++ testsuite/g++.dg/template/crash107.C (revision 0) @@ -0,0 +1,20 @@ +// PR c++/44625 +// { dg-do compile } +// { dg-options "" } + +template struct Vec { // { dg-message "note" } + Vec& operator^=(Vec& rhs) { + union { + struct {FP_ x,y,z;}; + }; // { dg-error "anonymous struct" } + X = y*rhs.z() - z*rhs.y(); // { dg-error "not declared|no member" } + } + Vec& operator^(Vec& rhs) { + return Vec(*this)^=rhs; // { dg-message "required" } + } +}; +Vec v(3,4,12); // { dg-error "no matching" } +// { dg-message "note" { target *-*-* } 16 } +Vec V(12,4,3); // { dg-error "no matching" } +// { dg-message "note" { target *-*-* } 18 } +Vec c = v^V; // { dg-message "required" } Index: cp/decl2.c =================================================================== --- cp/decl2.c (revision 175335) +++ cp/decl2.c (working copy) @@ -1327,7 +1327,10 @@ build_anon_union_vars (tree type, tree object) /* Rather than write the code to handle the non-union case, just give an error. */ if (TREE_CODE (type) != UNION_TYPE) - error ("anonymous struct not inside named type"); + { + error ("anonymous struct not inside named type"); + return error_mark_node; + } for (field = TYPE_FIELDS (type); field != NULL_TREE;