Attempting to bind a reference to a function where
the converted initializer is a glvalue whose
type is not call-compatible (
[expr.call])
with the type of the function's definition
results in undefined behavior
. Attempting to bind a reference to an object where
the converted initializer is a glvalue through which
the object is not type-accessible (
[basic.lval])
results in undefined behavior
. [
Note 2:
The object designated by such a glvalue can be
outside its lifetime (
[basic.life])
. Because a null pointer value or a pointer past the end of an object
does not point to an object,
a reference in a well-defined program cannot refer to such things;
see
[expr.unary.op]. As described in
[class.bit], a reference cannot be bound directly
to a bit-field
. —
end note]
[
Example 3:
int &f(int&);
int &g();
extern int &ir3;
int *ip = 0;
int &ir1 = *ip;
int &ir2 = f(ir3);
int &ir3 = g();
int &ir4 = f(ir4);
char x alignas(int);
int &ir5 = *reinterpret_cast<int *>(&x);
—
end example]