Thanks Nathan,

In fact, after testing with enums nested in namespaces or structs,

or function local, I realised nested specifiers should be printed

for both scoped and unscoped enums, but for unscoped enums one

level of nested specifier (the enum type) needs to be stripped.

So I inverted the IS_SCOPED test and used get_containing_scope:


if (value != NULL_TREE)
{

if (!ENUM_IS_SCOPED (type))

type = get_containing_scope (type);

pp_cxx_nested_name_specifier (pp, type);

pp->id_expression (TREE_PURPOSE (value));

}


I submitted this fix as a patch to the bug report, with tests.

With this fix GCC now has similar output to both Clang and MSVC
for enumerated values. For non-enumerated values GCC continues
to print a C-style cast while Clang & MSVC print plain digits.
Yay! GCC is winning! (gives type info for non-enumerated values).

A downside of nested specifiers is that output gets verbose.

Richard Smith suggests to use less verbose output for known types
compared to auto deduced types. Discussion starts here
http://lists.llvm.org/pipermail/cfe-dev/2018-September/059229.html

For enum args, I guess that this would mean distinguishing whether
the corresponding template parameter was auto or a given enum type
and only printing a simple id with no nested specs for given type.
I don't know yet if that info is available at the leaf level here.

Similarly, type info should be added to deduced Integral values.
I may start to investigate how to do this in GCC pretty print.
I submitted the related request to MSVC devs:
https://developercommunity.visualstudio.com/content/problem/339663/improve-pretty-print-of-integral-non-type-template.html

> given the code base ...

GCC pretty-print code was committed by GDR mid 2002,
K&R style C, updated to C90 'prototype' in mid 2003,
untouched since then, not for C++11 or C++17 enum updates.

I found this corner of the code base fairly easy to hack,
thanks perhaps to GDRs attempts to follow the grammar.


On Mon, Sep 24, 2018 at 3:53 PM Nathan Sidwell <nat...@acm.org> wrote:

> On 9/19/18 7:41 AM, will wray wrote:
> > Re: "Pretty print of enumerator never prints the id,
> >       always falls back to C-style cast output"
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87364
> >
>
> > I have a fix which duplicates the code in pp_c_enumeration_constant
> > to pp_cxx_enumeration_constant in cxx-pretty print, with modification
> >
> >    if (value != NULL_TREE)
> >    {
> >      if (ENUM_IS_SCOPED (type))
> >        pp_cxx_nested_name_specifier (pp, type);
> >      pp->id_expression (TREE_PURPOSE (value));
> >    }
> >
> > This works in my testing so far, but
> >   - It duplicates code from c to cxx (not DRY 'Don't Repeat Yourself)
> >   - I didn't find a single function to print full nested, scoped id
> >     so had to check if ENUM_IS_SCOPED to output nested specifiers.
>
> This seems a fine approach, given the code base.
>
> nathan
>
> --
> Nathan Sidwell
>

Reply via email to