2

The the 8th phase of translation was added in order to support the separate compilation model of templates that the community wished for; see N0818. However, since export was eventually removed (in C++11), it seems to me that it's not needed anymore. Here's my logic:

  • If a template specialization is referenced in a way that triggers an implicit instantiation, that implicit instantiation is performed during phase 7. As specified in [temp.pre]/10, the definition of the template must be available in the same translation unit unless there is an explicit instantiation in some other translation unit.
  • If there is an explicit instantiation in some other translation unit, that explicit instantiation is performed during phase 7 and is available during phase 9 to the translated translation units that require its definition.
  • Therefore, the standard no longer contemplates any scenario in which the decision of whether to instantiate a template defined in one TU depends on whether or not it is referenced by a different TU. But that was the whole point of phase 8, therefore phase 8 no longer does anything.
  • A compiler can still use the freedom granted by IFNDR in [temp.pre]/10 to perform the as-required instantiation that phase 8 was designed to support. However, it doesn't make sense to have a phase 8 just to say "if you choose not to diagnose the program, here is one thing you are allowed to do", since IFNDR allows the implementation to do anything anywaay.

Did I misunderstand anything?

Brian Bi
  • 111,498
  • 10
  • 176
  • 312
  • Inspired by: https://stackoverflow.com/q/43956379/481267 – Brian Bi Mar 23 '23 at 01:50
  • Hmm...I think a case can be made that: "Each translated translation unit is examined to produce a list of required instantiations." in phase 8 is then used in phase 9 to determine what explicit instantiations are required for a translated translation unit. None of the current phase descriptions really does a good job of describing what happens with inline variables either, where multiple TUs can each define the variable, but the linker then coalesces them all into a single definition in the program. – Jerry Coffin Mar 23 '23 at 04:01

0 Answers0