<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 12/10/13 9:02 PM, Richard Smith
wrote:<br>
</div>
<blockquote
cite="mid:CAOfiQqmBTTvySYU3O7sH9U0=Z2KCg5kJyx9skzsO1eYjuehFxA@mail.gmail.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">On Tue, Dec 10, 2013 at 4:48 AM,
Vassil Vassilev <span dir="ltr"><<a
moz-do-not-send="true"
href="mailto:vasil.georgiev.vasilev@cern.ch"
target="_blank">vasil.georgiev.vasilev@cern.ch</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi,<br>
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:<br>
<br>
template<typename T> T f(){ return T();}
template<> int f() { return 0;} // here clang will
inject a canonical declaration implicitly IIUC<br>
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:<br>
<br>
So my question is given the template specialization
definition could I distinguish between the both cases.</blockquote>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>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.</div>
</div>
</div>
</div>
</blockquote>
I didn't like the idea with comparing the source locations, because
it looks fragile to me.<br>
<br>
I am attaching the diff making the canonical decls for the
instantiations implicit. There are 3 failing tests with the patch
and 1 without. Looks like I got bad revision set. I will retry
tomorrow with newer llvm and clang to verify. I might be able to
produce a better patch and more intrusive though (please note that I
am not an expert in this):<br>
<br>
template<typename T> T f(){ return T();} template<> int
f(); template<> int f() { return 0;} <br>
Is there any reason why in the case of seeing the forward template
declaration of f to not 'canonicalize' it and add it as a template
specialization? Then the code around
SemaTemplateInstantiateDecl.cpp:1195 (with slight modifications)
will kick in and the redundant declaration could be avoided.<br>
<br>
Vassil<br>
<br>
</body>
</html>