This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Explicit instantiation and static objects in different modules


On Aug 4, 2015, at 20:32, Alexander Monakov <amonakov@ispras.ru> wrote:

> 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.
> 
> 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.

Thanks for pointing this out. I’ll use __attribute__ (noinline) for functions with static variables.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]