Bug 54948 - template unnecessarily displayed as "A< template-parameter-1-1 >" not "A<T>"
Summary: template unnecessarily displayed as "A< template-parameter-1-1 >" not "A<T>"
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2012-10-17 13:25 UTC by Jonathan Wakely
Modified: 2024-01-24 12:07 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-01-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2012-10-17 13:25:30 UTC
template<typename> struct A;

template<typename T> struct A { A(Y); };

A<int> a;

This invalid code produces:

tp.cc: In instantiation of 'struct A<int>':
tp.cc:5:8:   required from here
tp.cc:3:36: error: 'A< <template-parameter-1-1> >::Y' has incomplete type
 template<typename T> struct A { A(Y); };
                                    ^
tp.cc:3:29: error: declaration of 'struct A<int>'
 template<typename T> struct A { A(Y); };
                             ^

This is correct, but "A< <template-parameter-1-1> >::Y" is rather ugly.

At the point of the error the parameter has a name, so "A<T>::Y" could be shown instead.
Comment 1 Manuel López-Ibáñez 2013-04-19 16:39:45 UTC
I think there are other bugs about printing "template-parameter-1-1". I don't see why the pretty-printer may ever need to print such a thing.
Comment 2 Manuel López-Ibáñez 2013-04-20 12:03:29 UTC
There are several "bugs" in this case. The first one is that we consider that the type of:

template<typename> struct A

is "struct A< <template-parameter-1-1> >". It would be nicer to print something like "struct A<typename>" or "struct A<>". Clang never needs to print made up names.

The second bug is that I think we record T when parsing, but later we drop it. I wasn't able to find when we drop it. There is a lot going on between the moment we parse T and the moment we parse {, so it is rather difficult to figure out. Stepping in the parser is rather frustrating.

I am afraid that the only person that may know what is going or where to look is Jason. There is lookup_template_class, but by the time we call it, we already dropped T (or so it seems to me, maybe it is recorded somewhere else).
Comment 3 Manuel López-Ibáñez 2013-04-20 12:06:10 UTC
BTW, the parser may benefit by marking some functions with "skip" to help debugging. All the cp_lexer_peek_* are useless to step into.
Comment 4 Manuel López-Ibáñez 2013-04-20 12:50:26 UTC
Possibly related PR57014.
Comment 5 Jonathan Wakely 2022-01-18 13:24:12 UTC
This continues to be annoying. Libstdc++ has loads of forward declarations of templates, e.g. in <type_traits>:

  // Forward declarations
  template<typename>
    struct is_reference;
  template<typename>
    struct is_function;
  template<typename>
    struct is_void;
  template<typename>
    struct remove_cv;
  template<typename>
    struct is_const;

Which means we then get diagnostics containing:

std::is_same<_U1, typename std::remove_cv< <template-parameter-1-1> >::type&>

I agree with Manu that this could just show "typename" here. We don't refer to the template-parameter-1-1 type again in the diagnostic, so why do we care about uniquely identifying it as 1-1?

But why is it even using the name from the remove_cv declaration? That should not be appearing in the *use* of remove_cv here. I've filed that as PR 104094.