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]
Other format: [Raw text]

[Bug c++/11765] New: typecast vs. constructor ambiguity


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: typecast vs. constructor ambiguity
           Product: gcc
           Version: 3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hovik at melikyan dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i386-portbld-freebsd5.1
  GCC host triplet: i386-portbld-freebsd5.1
GCC target triplet: i386-portbld-freebsd5.1

	

G++ 3.3 gives an error message when there is an ambiguity between an explicit typecast operator
and a constructor, whereas all previous versions of g++ and also BCC and MSVC use the typecast
operator in this situation.

The appended code causes the following error:

gccbug.cxx: In function `int main()':
gccbug.cxx:27: error: call of overloaded `ClassOne(ClassTwo&)' is ambiguous
gccbug.cxx:3: error: candidates are: ClassOne::ClassOne(const ClassOne&)
gccbug.cxx:7: error:                 ClassOne::ClassOne(int)
gccbug.cxx:27: warning: unused variable `ClassTwo b'
*** Error code 1


Interestingly, there is no such constructor `ClassOne(ClassTwo&)' in the code, while gcc
calls it 'ambigious' in the message above.

Environment:
System: FreeBSD miles.netflute.com 5.1-RELEASE FreeBSD 5.1-RELEASE #0: Thu Jun 5 02:55:42 GMT 2003 root@wv1u.btc.adaptec.com:/usr/obj/usr/src/sys/GENERIC i386


host: i386-portbld-freebsd5.1
build: i386-portbld-freebsd5.1
target: i386-portbld-freebsd5.1
configured with: ./..//gcc-3.3/configure --disable-nls --with-gxx-include-dir=/usr/local/lib/gcc-lib/i386-portbld-freebsd5.1/3.3/include/c++/3.3 --with-system-zlib --disable-shared --prefix=/usr/local i386-portbld-freebsd5.1

How-To-Repeat:


class ClassOne
{
public:
    int data;

    ClassOne(int i)                      { data = i; }
};
        

class ClassTwo
{
public:
    int data;

    ClassTwo()                           { data = 0; }
    ClassTwo(const ClassOne& o)          { data = o.data; }

    operator int()                       { return data; }
    operator ClassOne()                  { return ClassOne(data); }
};


int main()
{
    ClassTwo a;
    ClassTwo b = ClassOne(a);
    return 0;
}


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