Consider the following sentence in the C++ standard:
Every program shall contain at least one definition of every function or variable that is odr-used in that program outside of a discarded statement; no diagnostic required. [...]
My intuition is that if a function or variable is odr-used, and no definitions exists anywhere, this results in a linker error in practice. It should be relatively easy for a compiler and linker to detect.
Is there ever a case where missing definitions in a program are too hard to diagnose, justifying this being IFNDR?
Is there ever a case where missing definitions in a program are too hard to diagnose, justifying this being IFNDR?
If a diagnostic was required, then the compiler would e.g. be forced to emit some reference to a function, even if the compiler knows that the call can never actually happen in order for the linker to detect and diagnose the missing definition.
For example:
void f();
int main() { if(false) f(); }
f()
is odr-using f
, but it is guaranteed to never be called which compiler optimizations can easily detect. So the compiler shouldn't have to emit a reference to f
just to provide an unnecessary diagnostic.
Depending on how you see dynamic libraries fitting into the standard's context, it would also make it impossible for them stay conforming, because dynamic linking typically doesn't require diagnosing missing definitions until load time or until a call actually happens.