From patchwork Fri Aug 31 12:36:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 964444 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-484858-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ASuNwOUB"; dkim-atps=neutral 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 4220kR2v8Wz9s1c for ; Fri, 31 Aug 2018 23:36:13 +1000 (AEST) Received: (qmail 117547 invoked by alias); 31 Aug 2018 12:36:08 -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 117530 invoked by uid 89); 31 Aug 2018 12:36:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS autolearn=ham version=3.3.2 spammy=surprise, HX-Received:9bc9, HX-Received:sk:w9-v6mr, wording X-HELO: mail-yb1-f169.google.com Received: from mail-yb1-f169.google.com (HELO mail-yb1-f169.google.com) (209.85.219.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 31 Aug 2018 12:36:07 +0000 Received: by mail-yb1-f169.google.com with SMTP id l16-v6so797525ybk.11 for ; Fri, 31 Aug 2018 05:36:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=3pq+6hMVcFA0x01BW5E3hEkD+CdaMTzPhSL2vlXFID4=; b=ASuNwOUBMIpr+FlDB3v0VEouWqhEU1n0NIcqD9xOVMtG6vtwgDqZRN1uyb1EvLqVos k5x3shqnKI6bzj2dK+tXVozHnEND3aLM+5efqyUm4SYJYQAh0v7bxn4VRKyLW2EIPThQ c3Dzsoa6Gj82FZhA6GbYjbwrdRp9DgFieMgb+I6Qz3o9uJBiMFMxpaLClQOHZZzCmSnq xOtwKBCSqvKUQAFJ60QVZzgYcEo/kE+26JDlbd6SnwUzcHi09hr2qdew06aRF2QG/dA2 C0IqakNeeZxv1MzCrjv9Jqdd8VHxoGkyDewuGIyYpVvZ6w0yVcAPFk+YsBpB15ew1jce 2hvg== Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::28ce]) by smtp.googlemail.com with ESMTPSA id d13-v6sm3795646ywd.20.2018.08.31.05.36.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Aug 2018 05:36:04 -0700 (PDT) Sender: Nathan Sidwell To: GCC Patches From: Nathan Sidwell Subject: [PR c++/87155] Anonymous namespace and Message-ID: Date: Fri, 31 Aug 2018 08:36:03 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 This fixes 87155 where an inline namespace caused us to find an inner anonymous namespace. The literal wording of the standard is wrong. Nobody implements that. They implement essentially 1 of 2 different interpretations, which were equivalent until inline namespaces and DR2061. Then one of those interpretations has a surprise! This patch implements the interpretation that gives us the desired behaviour. While we could implement that by giving anonymous namespaces names for lookup purposes, that started messing with the debug machinery and common core more than desirable. We can simply not look in inline namespaces when searching for a NULL name. It turns out that 84707 was similar case of this, that we considered ill formed (relying on our interpretation of the std). 84707 is well formed code. booted & tested on x86_64-linux, will commit trunk and gcc-8. nathan 2018-08-31 Nathan Sidwell PR c++/87155 PR c++/84707 cp/ * name-lookup.c (name_lookup::search_namespace): Don't look at inlines when searching for NULL names. testsuite/ * g++.dg/cpp0x/pr87155.C: New. * g++.dg/cpp0x/inline-ns10.C: Adjust. Index: gcc/cp/name-lookup.c =================================================================== --- gcc/cp/name-lookup.c (revision 264014) +++ gcc/cp/name-lookup.c (working copy) @@ -558,11 +558,14 @@ name_lookup::search_namespace (tree scop /* Look in exactly namespace. */ bool found = search_namespace_only (scope); - - /* Recursively look in its inline children. */ - if (vec *inlinees = DECL_NAMESPACE_INLINEES (scope)) - for (unsigned ix = inlinees->length (); ix--;) - found |= search_namespace ((*inlinees)[ix]); + + /* Don't look into inline children, if we're looking for an + anonymous name -- it must be in the current scope, if anywhere. */ + if (name) + /* Recursively look in its inline children. */ + if (vec *inlinees = DECL_NAMESPACE_INLINEES (scope)) + for (unsigned ix = inlinees->length (); ix--;) + found |= search_namespace ((*inlinees)[ix]); if (found) mark_found (scope); Index: gcc/testsuite/g++.dg/cpp0x/inline-ns10.C =================================================================== --- gcc/testsuite/g++.dg/cpp0x/inline-ns10.C (revision 264014) +++ gcc/testsuite/g++.dg/cpp0x/inline-ns10.C (working copy) @@ -2,7 +2,10 @@ // { dg-do compile { target c++11 } } inline namespace { - namespace {} + namespace {} // not this one + void a (); } -namespace {} // { dg-error "conflicts" } +namespace { + int a (); // { dg-error "ambiguating" "" } +} Index: gcc/testsuite/g++.dg/cpp0x/pr87155.C =================================================================== --- gcc/testsuite/g++.dg/cpp0x/pr87155.C (revision 0) +++ gcc/testsuite/g++.dg/cpp0x/pr87155.C (working copy) @@ -0,0 +1,14 @@ +// { dg-do compile { target c++11 } } +// PR c++/87155 confused about which anon namespace + +namespace { + void a (); // this one +} + +inline namespace n2 { + namespace {} +} + +namespace { + int a (); // { dg-error "ambiguating" "" } +}