[LLVMbugs] [Bug 20821] New: clang-cl doesn't accept two implicit conversions with a smart pointer pattern in the same way that MSVC does

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Aug 31 08:30:50 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20821

            Bug ID: 20821
           Summary: clang-cl doesn't accept two implicit conversions with
                    a smart pointer pattern in the same way that MSVC does
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ehsan at mozilla.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

$ cat test.cpp
template<class T>
struct SP {
  SP();
  SP(T*);
  void operator=(T*);
  operator T*();
};

struct B{};
struct D:B{};

void f() {
  SP<D> d;
  SP<B> b = d;
}

$ cl -c test.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 17.00.61030 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

test.cpp

$ clang-cl -c test.cpp
test.cpp(14,9) :  error: no viable conversion from 'SP<D>' to 'SP<B>'
  SP<B> b = d;
        ^   ~
test.cpp(2,8) :  note: candidate constructor (the implicit copy constructor)
not viable: no known conversion from 'SP<D>' to 'const SP<B> &' for 1st
      argument
struct SP {
       ^
test.cpp(2,8) :  note: candidate constructor (the implicit move constructor)
not viable: no known conversion from 'SP<D>' to 'SP<B> &&' for 1st argument

struct SP {
       ^
test.cpp(4,3) :  note: candidate constructor not viable: no known conversion
from 'SP<D>' to 'B *' for 1st argument
  SP(T*);
  ^
test.cpp(6,3) :  note: candidate function
  operator T*();
  ^
1 error generated.


It seems like MSVC first invokes SP::operator T*() and then invokes the ctor
taking the T* from it, which requires another implicit conversion from D* to
B*.  I don't think this is valid C++, but we may want to support it for compat
with MSVC.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140831/ce320482/attachment.html>


More information about the llvm-bugs mailing list