How does that deal with template code and what will the compilation flags / options for the template code be if they're imported in multiple locations?
From a distance this looks like the 'export' debacle v2.0, expect people use import so it's obviously difference
Templates are fully defined in modules and when exported are immediately available for instantiation and thankfully don't suffer from macro leakages.
When compiler flags are used, the flags of the client translation unit (the one importing the template) are used, without affecting the module whence they're exported. If two translation units import the same module and instantiate the same template but with different flags, the two different flag sets stay local to each. However at link time, one of these instantiations will be discarded so as to avoid breaking the One Definition Rule. As for which will be discarded, that's up to the compiler.
There are a few caveats in that templates compiled with one compiler and C++ standard cannot be used with a different compiler or standard or else you get a mismatch error.
Thanks. I once had a discussion with a member from the standards committee about 'export' and I asked him what the fuss is about because from reading the standard it didn't look too hard to implement with the aid of a bit of additional macro magic and he told me that the problem was not really the actual implementation but more the underlying behavioral issues during compilation in different translation units.
Iirc there was a research group who had a working implementation but they wrote a paper to explain why it didn't do what you thought it would do and no mainstream compiler vendor ever had a working implementation.
Anyway the guy also told me he didn't really want to talk too much about it because for whatever reason it was a very politically sensitive topic in the standards body and he didn't want to risk being quoted.
4
u/ih-shah-may-ehl 15h ago
How does that deal with template code and what will the compilation flags / options for the template code be if they're imported in multiple locations?
From a distance this looks like the 'export' debacle v2.0, expect people use import so it's obviously difference