[cfe-dev] Explicit instantiation with body?

John McCall rjmccall at apple.com
Wed Jun 19 11:42:44 PDT 2013


On Jun 19, 2013, at 10:59 AM, Larisse Voufo <lvoufo at google.com> wrote:
> On Wed, Jun 19, 2013 at 10:43 AM, John McCall <rjmccall at apple.com> wrote:
> On Jun 19, 2013, at 9:15 AM, Larisse Voufo <lvoufo at google.com> wrote:
> > Just out of curiosity, I have noticed that Clang currently allows the following program:
> >
> > template<typename T> T f() { return 13; }
> > template int f() { return 1; }
> >
> > It essentially parses the body of the explicit instantiation only to ignore it.
> > Was this a conscious decision?
> 
> I just spoke to Richard Smith about this, and it appears that the current behavior is a bit different from the way I just described it above. 
> The declaration for the template instantiation is parsed, but the 'template' keyword is ignored, which leads to two different behaviors for the calls f() and f<int>().
> While f() returns 1, f<int>() returns 13. f() picks up the declaration "int f() { return 1; }" while f<int>() picks up the template declaration and implicitly instantiates it.
>  
> 
> No;  please file a bug.  You cannot define a function in an explicit instantiation.
> 
> I can quickly fix this or submit a patch. Should I still file a bug? 

Fixing it is better. :)

> > GCC 4.6.3 rejects the program with "expected ‘;’ before ‘{’ token".
> 
> Well, hopefully we can do better than that. 
>  
> What do you have in mind? 

"error: cannot implement a function in an explicit instantiation"

or something along those lines.

John.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130619/54c0252c/attachment.html>


More information about the cfe-dev mailing list