* [pushed] c++: avoid redundant scope in diagnostics
@ 2021-12-03 22:20 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-12-03 22:20 UTC (permalink / raw)
To: 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
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" }
+}
base-commit: 7e71909af2cf3aeec9bed4f6a3cc42c1d17cd661
--
2.27.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-12-03 22:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-03 22:20 [pushed] c++: avoid redundant scope in diagnostics Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).