From patchwork Fri May 27 17:08:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 627301 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 3rGXXv0bB3z9sBm for ; Sat, 28 May 2016 03:08:46 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=HEzjK5do; 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 :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=Hc2ESPEV6/ujDfN6l T+Xv3Jsxw1n9+LVWK4Go+QloppLIZn5xX2dbWdU8JdIcRae9IEXCJHRjhCMjcluU hxEVAoMB0MBiDe7hMPku3eefZVkQb5YPfefSpyY1lMPtZnk5eRwREOcebBXKQKAX tJrfbGKnkpYeFsWzFrRqZxcbK8= 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 :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=QZsYIU1RAJktNysmAKhO4hl Nx9I=; b=HEzjK5doCI9srzSL2CShifY5M38qIrYDMA+NPLDXekuKlez12+F67xe 8TvTImpq7kLuhC8IPalEDEVcGglG2brz6/4Gfv8sRxpF82nS9VNE4gCG24e+a/Bn 8ssYp/iCP76v8NXNN8JGaeSsUxsMsw4rupoBzQQuzOZRxbGG/pN8= Received: (qmail 114261 invoked by alias); 27 May 2016 17:08: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 114241 invoked by uid 89); 27 May 2016 17:08:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=D*oracle.com, (unknown), friend X-HELO: userp1040.oracle.com Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 27 May 2016 17:08:27 +0000 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u4RH8Ps6013023 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 May 2016 17:08:25 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u4RH8OHC009166 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 May 2016 17:08:25 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u4RH8OVE013308; Fri, 27 May 2016 17:08:24 GMT Received: from [192.168.1.4] (/79.12.211.42) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 27 May 2016 10:08:24 -0700 Subject: Re: [C++ Patch/RFC] PR 60385 and other issues about wrongly named namespaces (eg, c++/68723) To: Jason Merrill , "gcc-patches@gcc.gnu.org" References: <57485F0F.2020907@oracle.com> <6948308b-86a3-ed29-0ad7-47d3df72713c@redhat.com> From: Paolo Carlini Message-ID: <57487F05.50408@oracle.com> Date: Fri, 27 May 2016 19:08:21 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: <6948308b-86a3-ed29-0ad7-47d3df72713c@redhat.com> X-IsSubscribed: yes Hi, On 27/05/2016 16:56, Jason Merrill wrote: > Let's go with the second patch. Good. Then I'm going to commit the below after an additional round of testing with an updated tree. Thanks! Paolo. /////////////////////// /cp 2016-05-27 Paolo Carlini PR c++/60385 * name-lookup.c (push_namespace): Return bool, false when pushdecl fails. * name-lookup.h (push_namespace): Adjust declaration. * parser.c (cp_parser_namespace_definition): Check push_namespace return value. /testsuite 2016-05-27 Paolo Carlini PR c++/60385 * g++.dg/parse/namespace13.C: New. Index: cp/name-lookup.c =================================================================== --- cp/name-lookup.c (revision 236830) +++ cp/name-lookup.c (working copy) @@ -3701,9 +3701,10 @@ handle_namespace_attrs (tree ns, tree attributes) } /* Push into the scope of the NAME namespace. If NAME is NULL_TREE, then we - select a name that is unique to this compilation unit. */ + select a name that is unique to this compilation unit. Returns FALSE if + pushdecl fails, TRUE otherwise. */ -void +bool push_namespace (tree name) { tree d = NULL_TREE; @@ -3777,7 +3778,11 @@ push_namespace (tree name) TREE_PUBLIC (d) = 0; else TREE_PUBLIC (d) = 1; - pushdecl (d); + if (pushdecl (d) == error_mark_node) + { + timevar_cond_stop (TV_NAME_LOOKUP, subtime); + return false; + } if (anon) { /* Clear DECL_NAME for the benefit of debugging back ends. */ @@ -3795,6 +3800,7 @@ push_namespace (tree name) current_namespace = d; timevar_cond_stop (TV_NAME_LOOKUP, subtime); + return true; } /* Pop from the scope of the current namespace. */ Index: cp/name-lookup.h =================================================================== --- cp/name-lookup.h (revision 236830) +++ cp/name-lookup.h (working copy) @@ -312,7 +312,7 @@ extern tree push_inner_scope (tree); extern void pop_inner_scope (tree, tree); extern void push_binding_level (cp_binding_level *); -extern void push_namespace (tree); +extern bool push_namespace (tree); extern void pop_namespace (void); extern void push_nested_namespace (tree); extern void pop_nested_namespace (tree); Index: cp/parser.c =================================================================== --- cp/parser.c (revision 236830) +++ cp/parser.c (working copy) @@ -17549,7 +17549,7 @@ cp_parser_namespace_definition (cp_parser* parser) } /* Start the namespace. */ - push_namespace (identifier); + bool ok = push_namespace (identifier); /* Parse any nested namespace definition. */ if (cp_lexer_next_token_is (parser->lexer, CPP_SCOPE)) @@ -17582,7 +17582,7 @@ cp_parser_namespace_definition (cp_parser* parser) /* "inline namespace" is equivalent to a stub namespace definition followed by a strong using directive. */ - if (is_inline) + if (is_inline && ok) { tree name_space = current_namespace; /* Set up namespace association. */ @@ -17610,7 +17610,8 @@ cp_parser_namespace_definition (cp_parser* parser) pop_namespace (); /* Finish the namespace. */ - pop_namespace (); + if (ok) + pop_namespace (); /* Look for the final `}'. */ cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE); } Index: testsuite/g++.dg/parse/namespace13.C =================================================================== --- testsuite/g++.dg/parse/namespace13.C (revision 0) +++ testsuite/g++.dg/parse/namespace13.C (working copy) @@ -0,0 +1,11 @@ +// PR c++/60385 + +float foo4(); // { dg-message "previous declaration" } + +namespace foo4 // { dg-error "redeclared" } +{ + struct bar6 + { + friend wchar_t bar1(); + }; +}