Reputation: 9835
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.
Upvotes: 6
Views: 157
Reputation: 40891
Every function that is odr-used requires a definition (no diagnostic required). Taking the address of a function is an odr-use, so this program exhibits undefined behaviour. With optimisations, the address-of is optimised out so it doesn't have a linker error, but it's not required to work.
Upvotes: 10