I would expect the following code to crash at runtime with a null pointer error:
#include <memory>
#include <iostream>
#include <cassert>
struct Foo {
void echo() {std::cout << "Echo" << std::endl;}
};
int main()
{
std::unique_ptr<Foo> up(new Foo());
up.reset(nullptr);
assert(up.get() == nullptr);
up.get()->echo();
}
however both gcc (4.7/4.8/4.9), msvc (2013 and upcoming 2015) and clang (3.5) happily outputs:
Echo
and assert is not firing so up.get()
is nullptr
.