C++标准问题

Any*_*orn 0 c++

如果以下结果导致未定义的行为?

应该指针2的值为NULL吗?

double *pointer = 0;
double &value = *pointer;
double *pointer2 = &value;
Run Code Online (Sandbox Code Playgroud)

Mic*_*urr 6

是.

double *pointer = 0;    // init `pointer` to a NULL pointer value
double &value = *pointer; // dereference it
Run Code Online (Sandbox Code Playgroud)

该标准专门针对这种情况 - 从8.3.2/4"参考文献":

应初始化引用以引用有效的对象或函数.[注意:特别是,在明确定义的程序中不能存在空引用,因为创建这样的引用的唯一方法是将它绑定到通过解引用空指针获得的"对象",这会导致未定义的行为.如9.6中所述,引用不能直接绑定到位字段.]