#include <string>

const
class {
public:
  template <class T> operator T() const
  {
    return T(); // even I change this to "return std::string();", same error.
  }

} MYNULLOBJECT = {};


int main()
{ 
  const unsigned int myInt(MYNULLOBJECT);    // OK, myInt is 0
  const std::string myString(MYNULLOBJECT);  // cannot compile
  return myInt;
}

my compiler output ====>
>g++ --version
g++ (GCC) 4.1.2
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

>g++  -g -c  test.C 
test.C: In function 'int main()':
test.C:17: error: call of overloaded 'basic_string(const<anonymous class>&)' is
ambiguous
/mnts/cdstools/gcc-4.1.2/linux-i386-2.3/include/c++/bits/basic_string.tcc:225:
note: candidates are: std::basic_string<_CharT, _Traits,
_Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char,
_Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/mnts/cdstools/gcc-4.1.2/linux-i386-2.3/include/c++/bits/basic_string.tcc:182:
note:                 std::basic_string<_CharT, _Traits,
_Alloc>::basic_string(const std::basic_string<_CharT, _Traits, _Alloc>&) [with
_CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/mnts/cdstools/gcc-4.1.2/linux-i386-2.3/include/c++/bits/basic_string.tcc:190:
note:                 std::basic_string<_CharT, _Traits,
_Alloc>::basic_string(const _Alloc&) [with _CharT = char, _Traits =
std::char_traits<char>, _Alloc = std::allocator<char>]
make: *** [test.o] Error 1


Please note that, this test case passed on SunCC compiler.


-- 
           Summary: call of overloaded 'basic_string(const<anonymous
                    class>&)' is ambiguous for a template member function
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gzljg at hotmail dot com


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

Reply via email to