I mean there's no reason you have to change everything by tomorrow. You could introduce it as a policy moving forward, the same way I'm sure you make any other changes to other patterns that need to be followed. I'm sure you have a process for this?
> Essentially, it was easier to write a compiler / linker optimization, than change the source code.
I agree, but see above and below.
> On the bright side, everyone wins!
Well, you waste space, time, and energy making the compiler and linker do work that doesn't inherently need to be done. You also lose parallelizability of the compilation of the two implementations if they currently reside in the same file. Finally the compiler (er, linker) might not be able to actually apply the devirtualizations you expect, whereas in this case it's just a matter of inlining since the target method is already known.
It's repetitive, error-prone work, better to have the compiler and linker do it than rely on the programmer getting their use of the preprocessor right.
And even if the programmer gets it right, doing it via macros means every tool that you want to apply to your codebase - IDEs, profilers, coverage, instrumentation - needs to understand your macro. Are you sure they'll all get it right?
Better to write plain old standard code that every tool will work correctly with, and the worst thing that can ever happen is a slight performance penalty.
Like the other commenter said, I'd rather do simple, virtual calls and then fix it using LTO.
You're suggesting that instead of a compiler wasting time space and energy, that we get actual people to waste their time space and energy by manually applying the transformation that the compiler is able to do anyway?
I don't know what you're referring to as the "suboptimal code" here. If it's the old pattern using virtual everywhere, then the ship's already sailed... that code is already in production. If you mean the two-file approach I proposed then that makes no sense; if it's worse than the last approach then why would you even use it.
So in this example you have to weigh the benefits of the two file tests against having tests that work uniformly.
"We do it that way here" is not something that has to be always applied.
Essentially, it was easier to write a compiler / linker optimization, than change the source code. On the bright side, everyone wins!