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