diff options
author | Jason Merrill <jason@redhat.com> | 2021-06-18 16:04:28 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2021-12-03 17:21:12 -0500 |
commit | f78eaffd1538efb46953a8bf90e9b95661fcfb33 (patch) | |
tree | a595c47d41da9f60490e44bfd4fba9ecdfc938f2 | |
parent | 7bfe82e5a850621f86867072022536c3f717d54c (diff) | |
download | gcc-f78eaffd1538efb46953a8bf90e9b95661fcfb33.zip gcc-f78eaffd1538efb46953a8bf90e9b95661fcfb33.tar.gz gcc-f78eaffd1538efb46953a8bf90e9b95661fcfb33.tar.bz2 |
c++: avoid redundant scope in diagnostics
We can make some function signatures shorter to print by omitting redundant
nested-name-specifiers in the rest of the declarator.
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.
-rw-r--r-- | gcc/cp/error.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/diagnostic/scope1.C | 12 |
2 files changed, 21 insertions, 1 deletions
diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 98c1f0e..daea3b3 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 0000000..14d0a1b --- /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" } +} |