c++/798: wrong templated operator lookup in custom namespace
Nicola.Musatti@ObjectWay.it
Nicola.Musatti@ObjectWay.it
Tue Nov 14 05:16:00 GMT 2000
>Number: 798
>Category: c++
>Synopsis: wrong templated operator lookup in custom namespace
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Tue Nov 14 05:16:01 PST 2000
>Closed-Date:
>Last-Modified:
>Originator: Nicola Musatti
>Release: GNU C++ version 2.95.2-3 19991024
>Organization:
>Environment:
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/2.95.2-3/specs
gcc driver version 2.95.2-3 19991024 (cygwin experimental) executing gcc version 2.95.2
/usr/lib/gcc-lib/i686-pc-cygwin/2.95.2-3/cpp.exe -lang-c++ -v -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -Di386 -D_X86=1 -D__STDC__=1 -D__stdcall=__attribute__((__stdcall__)) -D__cdecl=__attribute__((__cdecl__)) -D__declspec(x)=__attribute__((x)) -D__i386__ -D_X86=1 -D__STDC__=1 -D__stdcall=__attribute__((__stdcall__)) -D__cdecl=__attribute__((__cdecl__)) -D__declspec(x)=__attribute__((x)) -D__i386 -Asystem(winnt) -Acpu(i386) -Amachine(i386) -D__EXCEPTIONS -remap -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di686 -Dpentiumpro -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__ -D__CYGWIN32__ -D__CYGWIN__ -Dunix -D_WIN32 -DWINNT Lookup.cpp Lookup.ii
GNU CPP version 2.95.2-3 19991024 (cygwin experimental) (80386, BSD syntax)
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc-lib/i686-pc-cygwin/2.95.2-3/../../../../include/g++-3
/usr/lib/gcc-lib/i686-pc-cygwin/2.95.2-3/../../../../include
/usr/include
/usr/lib/gcc-lib/i686-pc-cygwin/2.95.2-3/include
/usr/include
End of search list.
The following default directories have been omitted from the search path:
End of omitted list.
/usr/lib/gcc-lib/i686-pc-cygwin/2.95.2-3/cc1plus.exe Lookup.ii -quiet -dumpbase Lookup.cc -version -o Lookup.s
GNU C++ version 2.95.2-3 19991024 (cygwin experimental) (i686-pc-cygwin) compiled by GNU C version 2.95.2 19991024 (release-2).
as -o Lookup.o Lookup.s
/usr/lib/gcc-lib/i686-pc-cygwin/2.95.2-3/collect2.exe -Bdynamic /usr/lib/crt0.o -L/usr/lib/gcc-lib/i686-pc-cygwin/2.95.2-3 Lookup.o -lgcc -lcygwin -luser32 -lkernel32 -ladvapi32 -lshell32 -lgcc
>Description:
The following program should return exit code 0, but returns 1 instead.
This is apparently caused by an error in operator == lookup.
The second friend defined one should be applied, but conversion to int takes
place instead and the built in operator == is called.
Note that the problem disappears by removing either the namespace
or the first friend operator == definition.
The problem has been recently discussed on comp.lang.c++.moderated
under the subject "Is this a gcc bug?". Here is the code:
namespace A {
template <typename T> class Nil {
public:
operator T () const { return T(); }
friend bool operator == (const Nil & lhs, const Nil & rhs) {
return true;
}
friend bool operator == (const Nil & lhs, const T & rhs) {
return true;
}
};
}
using namespace A;
int main(int argc, char* argv[]) {
int i = 5;
Nil<int> b;
return b == i ? 0 : 1;
}
>How-To-Repeat:
Compile, run the program and check the returned value.
It should be 0 but is 1 instead.
>Fix:
The problem can be worked around by removing the custom namespace
or the first overload of operator == from the source
(none of these options is viable for me)
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list