Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-cl doesn't accept two implicit conversions with a smart pointer pattern in the same way that MSVC does #21195

Closed
ehsan opened this issue Aug 31, 2014 · 2 comments
Labels
bugzilla Issues migrated from bugzilla c++ wontfix Issue is real, but we can't or won't fix it. Not invalid

Comments

@ehsan
Copy link
Contributor

ehsan commented Aug 31, 2014

Bugzilla Link 20821
Resolution WONTFIX
Resolved on Sep 02, 2014 11:08
Version trunk
OS All
CC @majnemer,@DougGregor,@zmodem,@jrmuizel,@rnk

Extended Description

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

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

void f() {
SP d;
SP 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' to 'SP'
SP b = d;
^ ~
test.cpp(2,8) : note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'SP' to 'const SP &' for 1st
argument
struct SP {
^
test.cpp(2,8) : note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'SP' to 'SP &&' for 1st argument

struct SP {
^
test.cpp(4,3) : note: candidate constructor not viable: no known conversion from 'SP' 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.

@zmodem
Copy link
Collaborator

zmodem commented Sep 2, 2014

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.

I'm surprised that they allow that (it seems to compile with the 14 CTP too). Unless we really can't avoid it, I don't think we should support this.

For smart pointers, I think the common thing to do is to provide templates for converting copy constructors and assignment operators, something like:

template SP {
...
template SP(SP other) { ... }
template void operator=(SP other);
}

I'll mark this wontfix for now.

@ehsan
Copy link
Contributor Author

ehsan commented Sep 2, 2014

Agreed on the wontfix, FWIW I fixed this issue on our side, just filed this so that we have a record of the issue!

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
@Quuxplusone Quuxplusone added the wontfix Issue is real, but we can't or won't fix it. Not invalid label Jan 20, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++ wontfix Issue is real, but we can't or won't fix it. Not invalid
Projects
None yet
Development

No branches or pull requests

3 participants