In a piece of code I reviewed lately, which compiled fine with g++-4.6
, I encountered a strange try to create a std::shared_ptr
from std::unique_
Here's a reduced example which clang incorrectly compiles:
struct ptr
{
int* p;
explicit operator bool() const { return p != nullptr; }
};
int main()
{
ptr u{};
int* p = new int(u);
}
Clang uses the explicit bool conversion operator to initialize the int
(and the Intel compiler does too.)
Clang 3.4 does not allow:
int i = int(u);
but it does allow:
int* p = new int(u);
I think both should be rejected. (Clang 3.3 and ICC allow both.)
I've added this example to the bug report.