https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79819
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Nikolay Bogoychev from comment #0) > Created attachment 40874 [details] > console output from failed compilation and *.ii files This attachment is a pain, is there really a need for each loader_file.ii to be in its own tar file? Also we can't debug a linker error with only a single file, even with four copies of the file. > What happens is that there is a static bool condition set at compile time, > which if set to true causes a certain function to be called which is only > compiled if that condition is set to true (If the condition is not set to > true, then the function would only be declared). This seems to work fine, > unless gcc6 -O0 compilation is used, at which point during the link stage > there's an undefined reference error. > > The gcc6 error is easily fixed if I add a definition of the offending > function, something like void foo() {} > > As far as I recall the compiler is going to try to execute all code paths, > even if the code would never be reached (eg. hidden by a static bool). > However does it complain if the function is only declared but not > implemented. Which one is the correct behavior? This sounds like a bug in your code. If you "odr-use" a function then it needs to be defined, even if it can never be reached at run-time e.g. const bool x = false; void foo(); int main() { if (x) foo(); } This requires a definition of void foo() even though it will never be called. Under certain conditions you don't get an error, such as when the compiler optimises away the call completely. But the rules of the language still say the definition is needed.