[cfe-dev] Function template specializations

Richard Smith richard at metafoo.co.uk
Tue Dec 10 12:02:30 PST 2013


On Tue, Dec 10, 2013 at 4:48 AM, Vassil Vassilev <
vasil.georgiev.vasilev at cern.ch> wrote:

> Hi,
>   IIUC when clang instantiates a function template it 'injects' a
> canonical declaration so that it can register it as a template
> specialization in the list of specializations. Is there any way to
> distinguish between implicitly 'injected' one and a forward declaration of
> the same. Eg:
>
>   template<typename T> T f(){ return T();} template<> int f() { return 0;}
> // here clang will inject a canonical declaration implicitly IIUC
>   template<typename T> T f(){ return T();} template<> int f(); template<>
> int f() { return 0;} // and here it won't because it was forward declared:
>
>   So my question is given the template specialization definition could I
> distinguish between the both cases.


Ideally we shouldn't generate this extra "bonus" declaration, but in
practice it's very useful (for detecting mismatches between the
specialization and the template, for instance). One way to distinguish
these cases is to compare source locations; if you get two redeclarations
of the same function template declaration at the same location, the first
one was the implicit one.

I'd take a patch to mark the implicitly-injected declaration with the
'Implicit' flag; that would give a much nicer way to detect this.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131210/23cc6e58/attachment.html>


More information about the cfe-dev mailing list