Suppose I have two translation units, both of which use std::string
. I compile one of them with -O3
, and the other without optimizations, then link the result together. Both object files would contain instantiated std::string
, but I would expect one version to be compiled with optimizations, and the other one without. Would the linker pick only one of those during linking? If so, which one? Will the resulting executable be guaranteed to always run properly?
Update: as this looks to be implementation-specific, it would make sense to narrow this down to gcc and clang behavior, since they both implement well-defined and concrete Itanium ABI, rather than trying to approach this from the point of view of the C++ standard itself.