This little code snippet compiles fine on gcc-3.x and 2.95. On 4.0 it produces 
an error of conflicting 
declarations of operator int to operator Foo<U>, whereas Foo<U> obviously is 
not an int. If you 
replace operator Foo<U> with operator Bar (not being templated) it works fine 
with gcc-4.0.

template <class T>
class Foo
{
 public:

        template <class U>
        operator Foo<U> () const
        { return Foo<U>(); }

        operator int () const
        { return 1; }

};

===============================================================
The compiler output:

g++ -v -save-temps -Wall -c tmpl_op.cc 
Reading specs from /usr/lib/gcc/powerpc-apple-darwin8/4.0.0/specs
Configured with: /private/var/tmp/gcc/gcc-4061.obj~8/src/configure 
--disable-checking --prefix=/
usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ 
--program-transform-name=/^
[cg][^+.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/gcc/darwin/4.0/c++ 
--build=powerpc-
apple-darwin8 --host=powerpc-apple-darwin8 --target=powerpc-apple-darwin8
Thread model: posix
gcc version 4.0.0 20041026 (Apple Computer, Inc. build 4061)
 /usr/libexec/gcc/powerpc-apple-darwin8/4.0.0/cc1plus -E -quiet -v 
-D__DYNAMIC__ tmpl_op.cc -
fPIC -Wall -fpch-preprocess -D__private_extern__=extern -o tmpl_op.ii
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory 
"/usr/lib/gcc/powerpc-apple-darwin8/4.0.0/../../../../powerpc-apple-
darwin8/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/gcc/darwin/4.0/c++
 /usr/include/gcc/darwin/4.0/c++/powerpc-apple-darwin8
 /usr/include/gcc/darwin/4.0/c++/backward
 /usr/lib/gcc/powerpc-apple-darwin8/4.0.0/include
 /usr/include
 /System/Library/Frameworks
 /Library/Frameworks
End of search list.
 /usr/libexec/gcc/powerpc-apple-darwin8/4.0.0/cc1plus -fpreprocessed tmpl_op.ii 
-fPIC -quiet -
dumpbase tmpl_op.cc -auxbase tmpl_op -Wall -version -D__private_extern__=extern 
-o tmpl_op.s
GNU C++ version 4.0.0 20041026 (Apple Computer, Inc. build 4061) 
(powerpc-apple-darwin8)
        compiled by GNU C version 4.0.0 20041026 (Apple Computer, Inc. build 
4061).
GGC heuristics: --param ggc-min-expand=56 --param ggc-min-heapsize=49152
tmpl_op.cc:12: error: declaration of 'Foo<T>::operator int() const'
tmpl_op.cc:8: error: conflicts with previous declaration 'Foo<T>::operator 
Foo<U>() const'

-- 
           Summary: Conflicting conversion operators ( one being templated
                    member function )
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: j dot uschok at btinternet dot com
                CC: gcc-bugs at gcc dot gnu dot org,j dot uschok at
                    btinternet dot com
  GCC host triplet: Darwin 8.2.0 Darwin Kernel Version 8.2.0: Fri Jun 24
                    17:46:54 PD


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22510

Reply via email to