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

Douglas Gregor dgregor at apple.com
Mon Jan 31 14:50:29 PST 2011


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.

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

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


More information about the cfe-dev mailing list