This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/3831: problem with forward declaration of function taking a reference to a generic member
- From: Nathanael Nerode <neroden at twcny dot rr dot com>
- To: gcc-gnats at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, lachaume at laog dot obs dot ujf dot grenoble dot fr, gcc-bugs at gcc dot gnu dot org, nobody at gcc dot gnu dot org
- Date: Fri, 3 Jan 2003 08:26:34 -0500
- Subject: Re: c++/3831: problem with forward declaration of function taking a reference to a generic member
- Reply-to: neroden at twcny dot rr dot com
3.4 behaves totally differently on the examples.
I believe the stated problem is fixed. However, I need to verify that the
two changes I made to the examples to get them to work are, in fact, fixes
needed to make the code legal. (If not, I have revealed other bugs...)
If the definition of struct A is moved above the forward declaration of g,
and the use of 'typename' inside the formal arguments is removed in all
cases, all is well.
--
template <typename u> struct A;
template <typename u> struct A {
template <typename v> struct B { };
};
template <typename u, typename v> void g(A<u>::B<v>&);
template <typename u, typename v> void g(A<u>::B<v>&);
int main() {
A<int>::B<float> b;
g<int, float>(b);
}
--
I believe that the definition of struct A needs to be above the declaration
of g because otherwise B isn't declared at the time of declaration of g. I
can't figure out a way to declare B before the definition of A. If there is
one in the C++ standard, I'll be happy to use it and see if that works.
I don't know why the 'typename' has to be removed from inside the arguments.
But it it isn't removed, g++ 3.4 does the same thing as it does if B isn't
declared before g: it decides that g is not a function (calls it a "variable
or field").
--Nathanael