[PATCH] Add gnu::diagnose_as attribute

Matthias Kretz m.kretz@gsi.de
Tue May 4 19:22:36 GMT 2021


> On Tuesday, 4 May 2021 15:34:13 CEST David Malcolm wrote:
> > Does the patch interact correctly with the %H and %I codes that try to
> > show the differences between two template types?

While looking into this, I noticed that given

namespace std {
  struct A {};
  typedef A B;
}

const std::B would print as "'const B' {aka 'const std::A'}", i.e. without 
printing the scope of the typedef. I traced it to cp/error.c (dump_type). In 
the `if (TYPE_P (t) && typedef_variant_p (t))` branch, in the final else 
branch only cv-qualifiers and identifier are printed:

  pp_cxx_cv_qualifier_seq (pp, t);
  pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t));

I believe the following should go in between, correct?

  pp_cxx_cv_qualifier_seq (pp, t);
  if (! (flags & TFF_UNQUALIFIED_NAME))
    dump_scope (pp, CP_DECL_CONTEXT (TYPE_NAME (t)), flags);
  pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t));

This is important for my diagnose_as patch because otherwise the output is:

  'const string' {aka 'const std::string'}

which is confusing and unnecessarily verbose. Patch below.


From: Matthias Kretz <kretz@kde.org>

dump_type on 'const std::string' should not print 'const string' unless
TFF_UNQUALIFIED_NAME is requested.

gcc/cp/ChangeLog:
	* error.c: Call dump_scope when printing a typedef.
---
 gcc/cp/error.c | 2 ++
 1 file changed, 2 insertions(+)


-- 
──────────────────────────────────────────────────────────────────────────
 Dr. Matthias Kretz                           https://mattkretz.github.io
 GSI Helmholtz Centre for Heavy Ion Research               https://gsi.de
 std::experimental::simd              https://github.com/VcDevel/std-simd
──────────────────────────────────────────────────────────────────────────
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-missing-scope-in-typedef-diagnostic.patch
Type: text/x-patch
Size: 427 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20210504/e2523046/attachment-0001.bin>


More information about the Libstdc++ mailing list