c++/10394: type inference gets confused during template instantiation
Giovanni Bajo
giovannibajo@libero.it
Mon Apr 14 01:24:00 GMT 2003
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&p
r=10394
Your code is ill-formed, and correctly rejected by any GCC version I have
(even if the error message could use a lifting).
To invoke correctly the function, you have to use this syntax:
a.f(typename A<typename V::X>::template B<int>());
Because:
- B<> is a nested template within A<>. A<> is dependent on C's template
parameter, so the keyword 'template' is needed in front of it to
disambiguate the parser.
- The whole expression A<typename V::X>::template B<int> refers to a type
name, which is dependent on C's template paremter, so the keyword 'typename'
is needed in front of it to disambiguate the parser.
Your line marked as [1] compiles because it is a function declaration, not
an object instantiation. Specifically, you're declaring a function called
"c" which returns an object of type C<E>, and accepts as parameter a pointer
to a function which gets no parameters and returns a A<int>.
Nonetheless, I found a regression on the mainline while playing with this:
-------------------------------------------------------
template <class T>
struct A
{
template <class U>
class B {};
};
template <class V>
struct C
{
C()
{
A<typename V::X>::template B<int> k;
}
};
struct E
{
typedef int X;
};
template struct C<E>;
int main()
{}
-------------------------------------------------------
pr10394.cpp: In constructor `C<V>::C()':
pr10394.cpp:13: error: expected `;'
pr10394.cpp: In constructor `C<V>::C() [with V = E]':
pr10394.cpp:22: instantiated from here
pr10394.cpp:13: internal compiler error: in resolve_offset_ref, at
cp/init.c:
1841
Please submit a full bug report,
on 3.4 20030413. Since the code is ill-formed (missing 'typename' keyword at
the start of the definition of k), this is a 3.4 regression,
ice-on-illegal-code. Previous versions (2.95 -> 3.3) reports some kind of
(unreadable) error message at least.
Giovanni Bajo
More information about the Gcc-bugs
mailing list