Is calling a nonvirtual member function on a non-constructed "object" well-defined?

Viewed 181

Inside a constructor, calling non-virtual member functions is permitted.

Does from this fact follow that the following piece of code is well-defined?

struct A {
    void foo { std::cout << "Hi there! My address is: " << this; }
};

A * a = nullptr;
a->foo ();

Answer?

With the help of some links given in the comments, and the links given in the linked pages, I now think that the answer can be found e.g. in

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3035.pdf

§3.8 par. 5, p. 66:

"Before the lifetime of an object has started but after the storage which the object will occupy has been allocated ... [t]he program has undefined behavior if [...] the pointer is used to access a non-static data member or call a non-static member function of the object"

Then it should be even more undefined to call a member function if storage has not been allocated at all.

I guess one important reason why it is a good idea to make it undefined is explained here: https://stackoverflow.com/a/3257755/1419315

1 Answers
Related