On Thursday, 27 January 2022 at 20:28:40 UTC, Siarhei Siamashka
wrote:
On Thursday, 27 January 2022 at 18:12:18 UTC, Johan Engelen
wrote:
But the language requires ODR, so we can emit templates as
weak_odr, telling the optimizer and linker that the symbols
should be merged _and_ that ODR can be assumed to hold (i.e.
inlining is OK).
Thanks! This was also my impression. But the problem is that
Iain Buclaw seems to disagree with us. He claims that template
functions must be overridable by global functions and this is
supposed to inhibit template functions inlining. Is there any
independent source to back up your or Iain's claim?
For example, druntime depends on this behaviour.
Template:
https://github.com/dlang/druntime/blob/a0ad8c42c15942faeeafb016e81a360113ae1b6b/src/rt/config.d#L46-L58
Regular symbol:
https://github.com/dlang/druntime/blob/a17bb23b418405e1ce8e4a317651039758013f39/test/config/src/test19433.d#L1
If we can rely on instantiated symbols to not violate ODR, then
you would be able to put symbols in the .link-once section.
However all duplicates must also be in the .link-once section,
else you'll get duplicate definition errors.