I realized the following compiles fine in GCC 4.7:
#include <memory>
int main() {
std::shared_ptr<int> p;
p = 0;
}
However, there is no assignment operator from int or from int*, and there is no implicit constructor from either int or int* either. There is a constructor from int*, but that one is explicit. I checked the standard library implementation and the constructor is indeed explicit, and no fishy assignment operators are in sight.
Is the program actually well-formed or is GCC messing with me?
The reason this works is this short quote from the standard:
§4.10 [conv.ptr] p1And the fact that
std::shared_ptrhas an implicit constructor fromstd::nullptr_t:§20.7.2.2 [util.smartptr.shared] p1This also allows for oddities like this:
Live example.