On Mar 15, 2010, at 7:57 AM, Rafael Espindola wrote:

>> +  } else if (Linkage == GVA_ExplicitTemplateInstantiation) {
>> +    // An explicit instantiation of a template has weak linkage, since
>> +    // explicit instantiations can occur in multiple translation units
>> +    // and must all be equivalent. However, we are not allowed to
>> +    // throw away these explicit instantiations.
>> +    return llvm::Function::WeakODRLinkage;
> 
> Just for curiosity, why does the c++ standard allows explicit
> instantiations in multiple translation units? I don't see the use of
> that and making a strong definition would make the linking more
> efficient.

I tried nudging C++0x in this direction, to allow us to emit strong definitions 
for some explicit instantiations, and there was resistance from the C++ 
committee. The concern is about the use case where we have a template from 
library A  with a type from library B in two different clients (C and D), both 
of which used the same instantiations and want to make sure that all of the 
members of that class template (in library A) are instantiated with that type 
(in library B). There might be some extern templates thrown in to control where 
the instantiation happens. Linking C and D together would then be ill-formed, 
and the committee didn't like that at all.

So, we need to use weak linkage for explicit instantiations. I'll write up a 
proposed extension for Clang (+ LLVM-GCC) that allows the use of some extra 
decoration to emit strong definitions.

        - Doug
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to