From patchwork Thu Feb 14 23:23:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1042477 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-496180-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="xMia/n7p"; 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 440rm45Mr9z9s3l for ; Fri, 15 Feb 2019 09:34:12 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=bAiex3retafUl93KI88rZ06K7y4K7iAt84NVfnN/gr2TBFmVSvmrJ p4JyipJAlvRPpfQ+I2c3Zp8lbpnxgGOnL8fgyzsQW7I8p+Cc/18hQxhSxJw9t4go Cb2xFNpnlwEgZMTnQ/Lhfx13DHgTREHuUy3RQyVmlegUZ09MyuZDnU= 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:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=Xuu0TA9sMZENjwhlJ+A1cBtTfJ0=; b=xMia/n7pFT/BsBCXDVGd 9vRcP9z1WBZeeDPZqjMzHgtkr6+wNpBrObAh80+TU1W+ANR69Z/kXlzEUJ7LGvpH g+PlMaB72E3weJ04gOZq8DuzptVlvDNQ5NXUg/gnrEXB/Mwh4/OTosLNvCkQ93GB OClIXORjxud/Q1kKchr4wZQ= Received: (qmail 59483 invoked by alias); 14 Feb 2019 22:33: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 59404 invoked by uid 89); 14 Feb 2019 22:33:23 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=offer 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; Thu, 14 Feb 2019 22:33:22 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 66289F9E64 for ; Thu, 14 Feb 2019 22:33:21 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-37.phx2.redhat.com [10.3.112.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40F405E7D5; Thu, 14 Feb 2019 22:33:20 +0000 (UTC) From: David Malcolm To: jakub@redhat.com, gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 2/7] C++: don't offer bogus "._0" suggestions (PR c++/86329) Date: Thu, 14 Feb 2019 18:23:39 -0500 Message-Id: <1550186624-25444-3-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1550186624-25444-1-git-send-email-dmalcolm@redhat.com> References: <1550186624-25444-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes PR c++/86329 reports that the C++ frontend can offer bogus suggestions like: #include int compare() { return __n1 - __n2; } suggested.cc: In function 'int compare()': suggested.cc:5:10: error: '__n1' was not declared in this scope return __n1 - __n2; ^~~~ suggested.cc:5:10: note: suggested alternative: '._61' return __n1 - __n2; ^~~~ ._61 suggested.cc:5:17: error: '__n2' was not declared in this scope return __n1 - __n2; ^~~~ suggested.cc:5:17: note: suggested alternative: '._72' return __n1 - __n2; ^~~~ ._72 The dot-prefixed names are an implementation detail of how we implement anonymous enums found in the header files, generated via anon_aggrname_format in make_anon_name. This patch uses anon_aggrname_p to filter them out when considering which names to suggest. gcc/cp/ChangeLog: Backport of r262199 from trunk. 2018-06-27 David Malcolm PR c++/86329 * name-lookup.c (consider_binding_level): Filter out names that match anon_aggrname_p. gcc/testsuite/ChangeLog: Backport of r262199 from trunk. 2018-06-27 David Malcolm PR c++/86329 * g++.dg/lookup/pr86329.C: New test. --- gcc/cp/name-lookup.c | 5 +++++ gcc/testsuite/g++.dg/lookup/pr86329.C | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/g++.dg/lookup/pr86329.C diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 86fa03b..4e8263b 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -5873,6 +5873,11 @@ consider_binding_level (tree name, best_match &bm, if (!suggestion) continue; + /* Don't suggest names that are for anonymous aggregate types, as + they are an implementation detail generated by the compiler. */ + if (anon_aggrname_p (suggestion)) + continue; + const char *suggestion_str = IDENTIFIER_POINTER (suggestion); /* Ignore internal names with spaces in them. */ diff --git a/gcc/testsuite/g++.dg/lookup/pr86329.C b/gcc/testsuite/g++.dg/lookup/pr86329.C new file mode 100644 index 0000000..fc091ba --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/pr86329.C @@ -0,0 +1,11 @@ +/* PR c++/86329: ensure we don't erroneously offer suggestions like "._0", + which are an implementation detail of how e.g. anonymous enums are + handled internally. */ + +enum {NONEMPTY}; + +int test() +{ + return __0; // { dg-error "'__0' was not declared in this scope" } + // { dg-bogus "suggested alternative" "" { target *-*-* } .-1 } +}