Re: Explicit instantiation and static objects in different modules

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 4 Aug 2015, Jonathan Wakely wrote:
> The extern template tells the compiler it doesn't *need* to
> instantiate the template, because it will be explicitly instantiated
> in another translation unit. But that doesn't mean it *must not*
> instantiate it. The compiler can choose to inline the function and in
> that case it will implicitly instantiate it. That should be
> unobservable because the One Definition Rule means that the implicitly
> instantiated definition that gets inlined and the explicitly
> instantiation definition in the other translation unit must be
> identical. The Windows linkage model seems to break that assumption
> ... so I don't know what the right behaviour is.

OK, thanks.  AFAIU, a very similar problem existed with GCC on Linux prior to
introduction of STB_GNU_UNIQUE (consider what happened when multiple DSOs with
a common singleton are loaded with RTLD_LOCAL -- they didn't have a way to end
up with a common location).

In light of that, perhaps it's best to structure code in a way that prevents
implementation of a singleton from being visible in translation units that can
be linked into different libraries.

Alexander



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux