From patchwork Fri Mar 28 10:01:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Butcher X-Patchwork-Id: 334635 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 27D63140082 for ; Fri, 28 Mar 2014 21:01:37 +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 :mime-version:content-type:content-transfer-encoding:date:from :to:cc:subject:in-reply-to:references:message-id; q=dns; s= default; b=naKGw7TltgIUmLrv8KlkaN9ueKLySzGXe0NixniV+cNmJrQKS4EwW 2XGVVXpZ2H7xwbVOYPcc4fDMRnkrDge7dxPGboqTcHyhnDXrGAy113bkHUUtr8D7 HPcKCYjU526/WTADE2mFFaHv7Q3GCARgM/Gt+SFkFrlJ201Lgfzu4M= 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 :mime-version:content-type:content-transfer-encoding:date:from :to:cc:subject:in-reply-to:references:message-id; s=default; bh= fZ9qzsoyJ4M5kcS439iOvnpB5WA=; b=QAxR7hvLbu7ziYrvM7wDnfNSRQ8FGxTI D6Pgwv2CPPuahvtR3Y8KC0mVBH+JUws9RG6CCfETAdCtny0Dg6QSvEsL9C6LMJcp B6GUHXVAHEM7VIFNbd7EtS6/OPRCz9wJip+apswe4YAz0Dx+ytei4TXkmaqmGtqW VwSUDfnEXmU= Received: (qmail 12514 invoked by alias); 28 Mar 2014 10:01:30 -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 12498 invoked by uid 89); 28 Mar 2014 10:01:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.3 required=5.0 tests=AWL, BAYES_50, KAM_COUK, RCVD_IN_DNSWL_LOW, WEBMAIL_BODY autolearn=no version=3.3.2 X-HELO: avasout07.plus.net Received: from avasout07.plus.net (HELO avasout07.plus.net) (84.93.230.235) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 28 Mar 2014 10:01:28 +0000 Received: from webmail.plus.net ([84.93.228.66]) by avasout07 with smtp id iy1R1n0011SbfYc01y1RoW; Fri, 28 Mar 2014 10:01:25 +0000 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=JIC1sq6b c=1 sm=1 tr=0 a=C5+YawzV8SR07mwocaP9vA==:117 a=rJgRRbfb+UpHm5KwX9t5uQ==:17 a=0Bzu9jTXAAAA:8 a=dYCPD3cKDi0A:10 a=5LfTt-Tm1vgA:10 a=EDeDkkTReK4A:10 a=IkcTkHD0fZMA:10 a=ZBkl__CYAAAA:8 a=mrHjP8x4AAAA:8 a=7vtFykjVAAAA:8 a=mDV3o1hIAAAA:8 a=SnTDmv-zDVDAhOZY1EcA:9 a=QEXdDO2ut3YA:10 a=ZoTwnPh0W0UA:10 X-AUTH: jessaminenet+adam:2501 Received: from munkyhouse.force9.co.uk ([84.92.244.81]) by webmail.plus.net with HTTP (HTTP/1.1 POST); Fri, 28 Mar 2014 10:01:25 +0000 MIME-Version: 1.0 Date: Fri, 28 Mar 2014 10:01:25 +0000 From: Adam Butcher To: Jason Merrill Cc: , Volker Reichelt Subject: Re: [PATCH] Fix PR c++/60573 In-Reply-To: <360c3656623433bfd2488eb279d19eba@imap.force9.net> References: <53345287.2030407@redhat.com> <1395953117-27334-1-git-send-email-adam@jessamine.co.uk> <360c3656623433bfd2488eb279d19eba@imap.force9.net> Message-ID: X-Sender: adam@jessamine.co.uk User-Agent: Roundcube Webmail/0.7.4 On 2014-03-27 21:16, Adam Butcher wrote: > On 2014-03-27 20:45, Adam Butcher wrote: >> PR c++/60573 >> * name-lookup.h (cp_binding_level): New field scope_defines_class_p. >> * semantics.c (begin_class_definition): Set scope_defines_class_p. >> * pt.c (instantiate_class_template_1): Likewise. >> * parser.c (synthesize_implicit_template_parm): Use >> cp_binding_level:: >> scope_defines_class_p rather than TYPE_BEING_DEFINED as the >> predicate >> for unwinding to class-defining scope to handle the erroneous >> definition of a generic function of an arbitrarily nested class >> within an >> enclosing class. >> > Still got issues with this. It fails on out-of-line defs. I'll have > another look. Turns out the solution was OK but I didn't account for the class-defining scope being reused for subsequent out-of-line declarations. I've made 'scope_defines_class_p' in to the now transient 'defining_class_p' predicate which is reset on leaving scope. I've ditched the 'scope_' prefix and also ditched the modifications to 'instantiate_class_template_1'. The patch delta is included below (but will probably be munged by my webmail client). I'll reply to this with the full patch. There is also the fix for PR c++/60626 (http://gcc.gnu.org/ml/gcc-patches/2014-03/msg01294.html) that deals with another form of erroneous generic function declarations with nested class scope. Cheers, Adam diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 53f14f3..0137c3f 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -1630,10 +1630,14 @@ leave_scope (void) free_binding_level = scope; } - /* Find the innermost enclosing class scope, and reset - CLASS_BINDING_LEVEL appropriately. */ if (scope->kind == sk_class) { + /* Reset DEFINING_CLASS_P to allow for reuse of a + class-defining scope in a non-defining context. */ + scope->defining_class_p = 0; + + /* Find the innermost enclosing class scope, and reset + CLASS_BINDING_LEVEL appropriately. */ class_binding_level = NULL; for (scope = current_binding_level; scope; scope = scope->level_chain) if (scope->kind == sk_class) diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h index 9e5d812..40e0338 100644 --- a/gcc/cp/name-lookup.h +++ b/gcc/cp/name-lookup.h @@ -255,9 +255,12 @@ struct GTY(()) cp_binding_level { unsigned more_cleanups_ok : 1; unsigned have_cleanups : 1; - /* Set if this scope is of sk_class kind and is the defining - scope for this_entity. */ - unsigned scope_defines_class_p : 1; + /* Transient state set if this scope is of sk_class kind + and is in the process of defining 'this_entity'. Reset + on leaving the class definition to allow for the scope + to be subsequently re-used as a non-defining scope for + 'this_entity'. */ + unsigned defining_class_p : 1; /* 23 bits left to fill a 32-bit word. */ }; diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 4919a67..0945bfd 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -32027,7 +32027,7 @@ synthesize_implicit_template_parm (cp_parser *parser) declarator should be injected into the scope of 'A' as if the ill-formed template was specified explicitly. */ - while (scope->kind == sk_class && !scope->scope_defines_class_p) + while (scope->kind == sk_class && !scope->defining_class_p) { parent_scope = scope; scope = scope->level_chain; diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 90faeec..c791d03 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -8905,12 +8905,9 @@ instantiate_class_template_1 (tree type) return type; /* Now we're really doing the instantiation. Mark the type as in - the process of being defined... */ + the process of being defined. */ TYPE_BEING_DEFINED (type) = 1; - /* ... and the scope defining it. */ - class_binding_level->scope_defines_class_p = 1; - /* We may be in the middle of deferred access check. Disable it now. */ push_deferring_access_checks (dk_no_deferred); diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index deba2ab..207a42d 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -2777,7 +2777,7 @@ begin_class_definition (tree t) maybe_process_partial_specialization (t); pushclass (t); TYPE_BEING_DEFINED (t) = 1; - class_binding_level->scope_defines_class_p = 1; + class_binding_level->defining_class_p = 1; if (flag_pack_struct) {