c++/3831: problem with forward declaration of function taking a reference to a generic member

lachaume@laog.obs.ujf.grenoble.fr lachaume@laog.obs.ujf.grenoble.fr
Thu Jul 26 05:56:00 GMT 2001


>Number:         3831
>Category:       c++
>Synopsis:       problem with forward declaration of function taking a reference to a generic member
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 26 05:56:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Régis Lachaume
>Release:        3.0 (release) and prior versions
>Organization:
>Environment:
gag237:cpp/bug $ uname -a
Linux gag237 2.4.0-test10 #3 mer déc 6 11:59:57 CET 2000 i686 unknown
gag237:cpp/bug $ ~/linux/bin/g++ -v
Reading specs from /gagax6/ur3/lachaume/linux/lib/gcc-lib/i686-pc-linux-gnu/3.0/specs
Configured with: ../configure --prefix=/gagax6/ur3/lachaume/indep --exec-prefix=/gagax6/ur3/lachaume/linux --enable-languages=c,c++ : (reconfigured) ../configure --prefix=/gagax6/ur3/lachaume/indep --exec-prefix=/gagax6/ur3/lachaume/linux --enable-languages=c++ --with-gxx-include-dir=/gagax6/ur3/lachaume/indep/include/g++ --with-local-prefix=/gagax6/ur3/lachaume/indep/
Thread model: single
gcc version 3.0
gag237:cpp/bug $ g++ -v
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux/2.95.3/specs
gcc version 2.95.3 19991030 (prerelease)
gag237:cpp/bug $ 
>Description:
g++ considers the forward declaration of a function taking a reference to a generic member and the definition of this function as two different declarations.
It issues the error ``call of overloaded ... is ambiguous''.

Example with g++ 2.95.3, bug also reproduced with g++ 3.0

gag237:cpp/bug $ more typename-light.cpp 
template <typename u> struct A;
template <typename u, typename v> void g(typename A<u>::B<v>&);

template <typename u> struct A {
   template <typename v> struct B { };
};

template <typename u, typename v> void g(typename A<u>::B<v>&);

int main() {
   A<int>::B<float> b;
   g<int, float>(b);
}
gag237:cpp/bug $ g++ -Wall -ansi -pedantic -W -O2 typename-light.cpp
typename-light.cpp: In function `int main()':
typename-light.cpp:12: call of overloaded `g (A<int>::B<float> &)' is ambiguous
typename-light.cpp:2: candidates are: void g<int, float>(A<int>::B<float> &)
typename-light.cpp:8:                 void g<int, float>(A<int>::B<float> &)
gag237:cpp/bug $ g++ --version
2.95.3
gag237:cpp/bug $ ~//linux/bin/g++ -Wall -W -ansi -pedantic -O2 -static -I/gagax6/ur3/lachaume/indep/include/g++-3.0 -I/gagax6/ur3/lachaume/indep/include/g++-3.0/i686-pc-linux-gnu/ -o typename typename.cpp
typename.cpp: In function `int main()':
typename.cpp:26: call of overloaded `g(A<int>::B<float>&)' is ambiguous
typename.cpp:13: candidates are: void g(typename A<u>::B<v>&) [with u = int, v 
   = float]
typename.cpp:20:                 void g(A<u>::B<v>&) [with u = int, v = float]
typename.cpp:27: call of overloaded `h(A<int>::B<float>&)' is ambiguous
typename.cpp:14: candidates are: void h(typename A<u>::B<v>&) [with u = int, v 
   = float]
typename.cpp:21:                 void h(const A<u>::B<v>&) [with u = int, v = 
   float]
gag237:cpp/bug $ ~/linux/bin/g++ --version
3.0
gag237:cpp/bug $

Other problems: 
* a missing typenames in the definition is not diagnosed with the -pedantic option.
* g++ v >= 3.0 ignores an eventual const qualifier in the forward declaration when reporting the error, whereas g++ 2.95.3 does it correctly

A full example file is attached.
>How-To-Repeat:

>Fix:
No idea.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="typename.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="typename.cpp"

Ly8gZm9yd2FyZCBkZWNsYXJhdGlvbiBvZiBhIGZ1bmN0aW9uIHRha2luZyBhIGdlbmVyaWMgbWVt
YmVyCgovLyBQcm9ibGVtcyB3aXRoIGdjYyAzLjAKLy8gICAxLiBlcnJvciBgYGFtYmlndW91cyBv
dmVybG9hZGVkIC4uLicnCi8vICAgMi4gbm8gd2FybmluZyB3aXRoIG1pc3Npbmcgd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