From patchwork Fri Dec 3 22:20:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 48483 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 412DC3858C3A for ; Fri, 3 Dec 2021 22:21:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 412DC3858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638570076; bh=8HP1fBXEPe7sGIxIITCV4j2k20/vhCv2I0lVxPHQ0ls=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=lqjw5h171Lhjz4rjTcF0bSos4JY333fD2k8KwNhcKLTjkIhJUNN9N8752VonJ4k46 Jdm3Ilc1hRBJPpQu69eSZ1wX+ktwiyBPAdht8Zd+u4P5Kl6y5YOBrmmWQUiRv53iQ4 V5rwKGSxzvJQuRsA1WV2noWYcEDVEL8bEUuuacmU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 20CCD3858D28 for ; Fri, 3 Dec 2021 22:20:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 20CCD3858D28 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-459-CMYkA9rBOhG92Xq3BGXC3w-1; Fri, 03 Dec 2021 17:20:44 -0500 X-MC-Unique: CMYkA9rBOhG92Xq3BGXC3w-1 Received: by mail-qt1-f199.google.com with SMTP id p7-20020ac84087000000b002b60be80b27so5097638qtl.18 for ; Fri, 03 Dec 2021 14:20:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=8HP1fBXEPe7sGIxIITCV4j2k20/vhCv2I0lVxPHQ0ls=; b=acaT/tTZs0Z2dnYWTnMW2fVa8P7eRCIqHQnZG08QeFkJ//BCr+bNtFQ4yDWosdpqSJ WUzWiQttTVTjUla9Ueu6Gj6U6oJH6NGMB45hW/gVYq9pQkyEcZScifcqxSAsrjJDd5UQ +tGENIJaPaw+NNpGYaRk4mwWBueXxEvxRNBoF8wZAh2Dt+U0NEWa3HGzCAwcGNX6g3tm GdbqiNYBf364nsQGmOAeXKpZaSwzpiWz1fHXdgGG4KKrgpTuvIUq11M4PCiG8RHCAI/D S7kAOFmn/8hg5LxFGQ3QXHw1fdS0yTYY1L9oolPDStZSpmPTkJNnLy/T9iBxMYcazwOO I1dQ== X-Gm-Message-State: AOAM5306dwgmtTd7IGlFrSLD6RR/CEefXnUWNvVLIi2ITUCaiMt9IoAO P4TL97kp/CUQnysje51E2zCkntV8APp+mxsQvYHmi3PUtEwG7THZQkQCsn3ll3hwvHNB6ysNW0B cFzk/qsTsosUut3gMvpx0jPU/5105rCQ9Ey07yIm0kKIJW3wmLowFGcnNbF6vlv2BqA== X-Received: by 2002:a05:620a:118c:: with SMTP id b12mr20710790qkk.303.1638570043433; Fri, 03 Dec 2021 14:20:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJz3eAEfs0lntzjPTqXj/F6y36VaQ+2qgmw0zZZAvfp3WcMe6gPL0MeIDL2cN7l6OkC6znPguA== X-Received: by 2002:a05:620a:118c:: with SMTP id b12mr20710756qkk.303.1638570042933; Fri, 03 Dec 2021 14:20:42 -0800 (PST) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id x16sm2904279qko.15.2021.12.03.14.20.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:20:42 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: avoid redundant scope in diagnostics Date: Fri, 3 Dec 2021 17:20:39 -0500 Message-Id: <20211203222039.3639438-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" We can make some function signatures shorter to print by omitting redundant nested-name-specifiers in the rest of the declarator. Tested x86_64-pc-linux-gnu, applying to trunk. gcc/cp/ChangeLog: * error.c (current_dump_scope): New variable. (dump_scope): Check it. (dump_function_decl): Set it. gcc/testsuite/ChangeLog: * g++.dg/diagnostic/scope1.C: New test. --- gcc/cp/error.c | 10 +++++++++- gcc/testsuite/g++.dg/diagnostic/scope1.C | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/diagnostic/scope1.C base-commit: 7e71909af2cf3aeec9bed4f6a3cc42c1d17cd661 diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 98c1f0e4bdf..daea3b39a15 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -211,6 +211,10 @@ dump_module_suffix (cxx_pretty_printer *pp, tree decl) } } +/* The scope of the declaration we're currently printing, to avoid redundantly + dumping the same scope on parameter types. */ +static tree current_dump_scope; + /* Dump a scope, if deemed necessary. */ static void @@ -218,7 +222,7 @@ dump_scope (cxx_pretty_printer *pp, tree scope, int flags) { int f = flags & (TFF_SCOPE | TFF_CHASE_TYPEDEF); - if (scope == NULL_TREE) + if (scope == NULL_TREE || scope == current_dump_scope) return; /* Enum values within an unscoped enum will be CONST_DECL with an @@ -1756,6 +1760,10 @@ dump_function_decl (cxx_pretty_printer *pp, tree t, int flags) else dump_scope (pp, CP_DECL_CONTEXT (t), flags); + /* Name lookup for the rest of the function declarator is implicitly in the + scope of the function, so avoid printing redundant scope qualifiers. */ + auto cds = make_temp_override (current_dump_scope, CP_DECL_CONTEXT (t)); + dump_function_name (pp, t, dump_function_name_flags); if (!(flags & TFF_NO_FUNCTION_ARGUMENTS)) diff --git a/gcc/testsuite/g++.dg/diagnostic/scope1.C b/gcc/testsuite/g++.dg/diagnostic/scope1.C new file mode 100644 index 00000000000..14d0a1bfab6 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/scope1.C @@ -0,0 +1,12 @@ +// Test for avoiding redundant scope qualifiers. + +struct A +{ + struct B { }; + static void f(B,B); // { dg-message {A::f\(B, B\)} } +}; + +int main() +{ + A::f(42); // { dg-error "no match" } +}