When does calling a member function on a null instance result in undefined behavior in C ++ 11?

Possible duplicate:
When calls a member function on a null instance as a result of undefined execution?

I just read this question with a great answer: When does a member function call on a null instance in undefined behavior?

Basically, is the following code undefined behavior?

struct foo { static void bar() { } };
foo *p = nullptr;
p->bar();

      

According to the linked post, this can be interpreted in different ways one of which is UB and the other is not.

In C ++ 0x starting from n3126, uncertainty remains

Does this hold true with the final C ++ 11?

+3


source to share


1 answer


The question you are referring to clearly shows that in a strict or weak interpretation of the standard, the code you are showing is undefined behavior. The ambiguity (can) only exists for static functions (and your question is specific to non-stationary functions).



EDIT: The uncertainty remains as N3337

of 2012-01-16 for now, but I don't have a copy of the final standard. Based on the comments in this question, it looks like the 232 release resolution never made it into the standard, presumably because the wording was too strong to make it a compile-time concept and not undefined in its own way.

+5


source







All Articles