The following code defines the entire program. Is this program standard conformant (with the latest version)?
void foo();
int main()
{
auto x = &foo;
return 0;
}
Here is a convenience shortcut.
This code has no practical use, I'm just curious.
x
in some way, it doesn't compile: godbolt.org/z/DaisTo – Palmx
is used or not, it should apply here too. – Blackandwhitex
is used either. The standard doesn't prevent a compiler from eliminating variables (likex
), or evaluation of expressions that initialise them (&foo
), if it can detect there are no side-effects of the initialisation or usage of the variable. The "as if" rule only requires observable behaviour to be the same. Sincefoo()
is not defined in the program the behaviour is undefined, no diagnostic required - and one possible manifestation of that is a linker error (missing symbolfoo()
) but that is not required – Covariance