c++/401: error with friend / template combination

tanis@gaspode.franken.de tanis@gaspode.franken.de
Tue Jul 11 12:06:00 GMT 2000


>Number:         401
>Category:       c++
>Synopsis:       error with friend / template combination
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Tue Jul 11 12:06:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     German Tischler
>Release:        gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
FreeBSD 5.0-CURRENT i386
>Description:
G++ seems to have problems with names in
template classes. It refuses to have a
name and a friend with the same name in
one class definition.
It complains about a non-existant forward
declaration.
>How-To-Repeat:
Source:

template < typename N > struct A;
template < typename N > A<N> operator+ (A<N> const &, A<N> const &);

template < typename N > struct A
{
        A<N> const & operator+() const;
        friend A<N> operator+<N> (A<N> const &, A<N> const &);
};

A<bool> b;

Command Line:
c++ -v --save-temps -c dumb3.cpp -o dumb3.o

Output:

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 -Dunix -D__FreeBSD__=5 -D__FreeBSD_cc_version=500001 -D__i386__ -D__unix__ -D__FreeBSD__=5 -D__FreeBSD_cc_version=500001 -D__i386 -D__unix -Acpu(i386) -Amachine(i386) -Asystem(unix) -Asystem(FreeBSD) -D__EXCEPTIONS -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__ELF__ dumb3.cpp dumb3.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 dumb3.ii -quiet -dumpbase dumb3.cc -version -o dumb3.s
GNU C++ version 2.95.2 19991024 (release) (i386-unknown-freebsd) compiled by GNU C version 2.95.2 19991024 (release).
dumb3.cpp: In instantiation of `A<bool>':
dumb3.cpp:10:   instantiated from here
dumb3.cpp:7: invalid use of undefined type `struct A<bool>'
dumb3.cpp:8: forward declaration of `struct A<bool>'
dumb3.cpp:7: confused by earlier errors, bailing out                            

Comment:
The code is compiled, if you leave one of the two
lines inside the struct definition away.
>Fix:
unknown
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="dumb3.ii"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="dumb3.ii"

IyAxICJkdW1iMy5jcHAiCnRlbXBsYXRlIDwgdHlwZW5hbWUgTiA+IHN0cnVjdCBBOwp0ZW1wbGF0
ZSA8IHR5cGVuYW1lIE4gPiBBPE4+IG9wZXJhdG9yKyAoQTxOPiBjb25zdCAmLCBBPE4+IGNvbnN0
ICYpOwoKdGVtcGxhdGUgPCB0eXBlbmFtZSBOID4gc3RydWN0IEEKewoJQTxOPiBjb25zdCAmIG9w
ZXJhdG9yKygpIGNvbnN0OwoJZnJpZW5kIEE8Tj4gb3BlcmF0b3IrPE4+IChBPE4+IGNvbnN0ICYs
IEE8Tj4gY29uc3QgJik7Cn07CgpBPGJvb2w+IGI7Cg==


More information about the Gcc-prs mailing list