[cfe-dev] Function Instantiation: Where? Or is it?

Douglas Gregor dgregor at apple.com
Mon Jan 31 15:19:52 PST 2011


On Jan 31, 2011, at 3:18 PM, Larisse Voufo wrote:

> 
> 
> On Mon, Jan 31, 2011 at 5:50 PM, Douglas Gregor <dgregor at apple.com> wrote:
> 
> On Jan 31, 2011, at 1:43 PM, Larisse Voufo wrote:
> 
>> Thanks. That was a lot helpful. However, I do have another question. Consider the following two case scenari: 
>> 
>> Case 1:
>> ------------
>> The previous one, with
>> (1) f() defined as a concept member, and
>> (2) func() a restricted template
>> 
>> 
>> Case 2:
>> ------------
>> (1) f() is a global function, and
>> (2) func() is a simple template, as in
>> 
>> void f() { }
>> 
>> template<typename T>
>> void func(T a) {
>>     f(0);
>> }
>> 
>> int main(int argc, char **argv) 
>> { 
>>     int i=0;
>>     func<int>(i); 
>> }
>> 
>> 
>> Observation:
>> ----------------------
>> In both cases, f() never seems to be "marked for instantiation", at least not through Sema::
>> MarkDeclarationReferenced. However, f() does seem to eventually get instantiated in the "Case 2" somehow, whereas it never does in "Case 1". Any idea?
>> 
>> 1) When does f() get instantiated in "Case 2"?
> 
> Case 2 is ill-formed, but the general rule is that MarkDeclarationReferenced will get called when we use that function in a potentially evaluated context, either in non-template code or during template instantiation.
> 
> Sorry about this. I meant for the definition of f() to take an integer in as argument...  
>  
>> 2) is this connected to lookup somehow?
>>      I have made some very minor changes in Sema::CppLookupName(), and I'm not sure how this could affect instantiation...
> 
> 
> It's more likely that you haven't added any logic to permit the instantiation of functions defined within concept maps.
> 
> Any rule of thumb on how to add such logic? Say, for example how is this currently setup for  "(corrected) Case 2"?

Please see the handling of function templates in Sema::MarkDeclarationReferenced and the actual instantiation in Sema::InstantiateFunctionDefinition. It probably needs a small tweak for concept maps, but there's no more advice anyone can give without looking specifically at your representation of concept maps.

	- Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110131/5fa1bdca/attachment.html>


More information about the cfe-dev mailing list