This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

c++/2482: friend template function and class member can't overload in a class template



>Number:         2482
>Category:       c++
>Synopsis:       friend template function and class member can't overload in a class template
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Apr 03 23:56:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Gregory Bond, ITG Australia Ltd
>Release:        gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
FreeBSD 4.2 (but also reproduced on a Sparc system with 2.95.0)
>Description:
A class template with a template function as a friend
cannot have a member with the same name (and different 
signature).  Attempts to do do elicit bogus error messages 
about invalid types and forward declarations.

The equivalent non-template code works as expected, with 
the member foo() able to overload with the friend foo().

In this sample the member is "foo()" but was originally
found with "operator+()" - so obviously using another name
is not an option here!

Running against the codesourcery 3.0 prerelease web page 
version elicits different (but afaict still bogus) errors:

Reading specs from /usr/local/bin/../lib/gcc-lib/i386-pc-linux-gnu/3.0/specs
     Configured with: ../configure --prefix=/tmp/gcc-20010327-root/usr/local --enable-shared --enable-threads --disable-checking i386-pc-linux-gnu : (reconfigured) 
     gcc version 3.0 20010327 (prerelease)
      /usr/local/bin/../lib/gcc-lib/i386-pc-linux-gnu/3.0/cc1plus -v -iprefix /usr/local/bin/../lib/gcc-lib/i386-pc-linux-gnu/3.0/ -D__GNUC__=3 -D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__STDC_HOSTED__=1 -Wall -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i386__ /tmp/@11275.7.cc -D__GNUG__=3 -D_GNU_SOURCE -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -quiet -dumpbase @11275.7.cc -Wall -version -o /tmp/cc46PR1q.s
     GNU CPP version 3.0 20010327 (prerelease) (cpplib) (i386 Linux/ELF)
     GNU C++ version 3.0 20010327 (prerelease) (i386-pc-linux-gnu)
             compiled by GNU C version 3.0 20010327 (prerelease).
     ignoring nonexistent directory "/tmp/gcc-20010327-root/usr/local/include/g++-v3"
     ignoring nonexistent directory "/tmp/gcc-20010327-root/usr/local/include/g++-v3/i386-pc-linux-gnu"
     ignoring nonexistent directory "/tmp/gcc-20010327-root/usr/local/lib/gcc-lib/i386-pc-linux-gnu/3.0/include"
     ignoring nonexistent directory "/tmp/gcc-20010327-root/usr/local/i386-pc-linux-gnu/include"
     #include "..." search starts here:
     #include <...> search starts here:
      /usr/local/include/g++-v3
      /usr/local/include/g++-v3/i386-pc-linux-gnu
      /usr/local/lib/gcc-lib/i386-pc-linux-gnu/3.0/include
      /usr/local/i386-pc-linux-gnu/include
      /usr/local/include
      /usr/include
     End of search list.
     /tmp/@11275.7.cc:13: declaration of `void A::foo(int) const'
     /tmp/@11275.7.cc:3: changes meaning of `foo' from `void foo(int, A)'


>How-To-Repeat:
hellcat$ c++ -v -Wall t.C
Using builtin specs.
gcc version 2.95.2 19991024 (release)
 /usr/libexec/cpp -lang-c++ -v -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -Di386 -D__FreeBSD__=4 -D__FreeBSD_cc_version=430000 -Dunix -D__i386__ -D__FreeBSD__=4 -D__FreeBSD_cc_version=430000 -D__unix__ -D__i386 -D__unix -Acpu(i386) -Amachine(i386) -Asystem(unix) -Asystem(FreeBSD) -D__EXCEPTIONS -Wall -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__ELF__ t.C /tmp/cc6oEzY4.ii
GNU CPP version 2.95.2 19991024 (release) (i386 FreeBSD/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/g++
 /usr/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
End of omitted list.
 /usr/libexec/cc1plus /tmp/cc6oEzY4.ii -quiet -dumpbase t.cc -Wall -version -o /tmp/ccSGczHf.s
GNU C++ version 2.95.2 19991024 (release) (i386-unknown-freebsd) compiled by GNU C version 2.95.2 19991024 (release).
t.C: In instantiation of `A<int>':
t.C:17:   instantiated from here
t.C:10: invalid use of undefined type `class A<int>'
t.C:15: forward declaration of `class A<int>'
hellcat$ 
>Fix:
Use friend functions for all cases instead of a mixture
of friend and member functions.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="t.C"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="t.C"

dGVtcGxhdGUgPGNsYXNzIFQ+IGNsYXNzIEE7Cgp0ZW1wbGF0ZSA8Y2xhc3MgVD4gdm9pZCBmb28o
aW50LCBBPFQ+KTsKLy90ZW1wbGF0ZSA8Y2xhc3MgVD4gdm9pZCBmb28oQTxUPiwgaW50KTsKCnRl
bXBsYXRlIDxjbGFzcyBUPgpjbGFzcyBBIAp7CnB1YmxpYzoKICBmcmllbmQgdm9pZCBmb28gPD4o
aW50LCBBKTsKCiAgLy9mcmllbmQgdm9pZCBmb28gPD4oQSwgaW50KTsJLy8gVGhpcyB3b3JrcyAo
d2l0aCB0aGUgZGVmIGFib3ZlKQogIHZvaWQgZm9vKGludCkgY29uc3Q7CQkvLyBUaGlzIGZhaWxz
LgogICAgCn07CgpBPGludD4gYTsKCg==


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]