I noticed that when linking a project using G++, if there are functions that are declared, but not implemented, there are no errors, unless I try to call them.
Q1: Is it possible to enable an error (or at least warning) if a function is declared but not implemented?
Q2: Why this behavior?
(Note: I am using G++ 4.7.0, ld 2.22 if that is the linker used by gcc, from the mingw package)
A2: An entity such as a non-inline function with external linkage can have zero or one definitions in a program. It is only required to have one definition if it is actually used (strictly odr-used) - e.g. by being called. g++ would be in error if it issued an error for an undefined function that wasn't used.
A1: So it is not possible (in a conforming way) to force this to be an error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With