<div dir="ltr">I'm not entirely clear on where the warnings are/aren't here, but some general advice:<br><br>Warnings should usually only be issued from either template patterns of template instantiations, not both. If the error can be detected in a pattern (either because it's in a non-dependent expression, or the dependence of the expression doesn't matter to the test) that's better because you can warn exactly once no matter how many instantiations there are.<br><br>Otherwise, defer to the instantiations.</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Apr 12, 2017 at 2:11 AM Alex L via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">Hi,<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I have observed something slightly different - both the dependent and non-dependent non-instantiated TypedefDecl are marked as referenced (ToT clang). It seems to me that you could try fixing the issue by marking the instantiated TypedefDecls as referenced if the non-instantiated is referenced (see TemplateDeclInstantiator::InstantiateTypedefNameDecl).</div></div><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Alex</div></div><div class="gmail_extra gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg">On 12 April 2017 at 08:29, Johannes Altmanninger via cfe-dev <span dir="ltr" class="gmail_msg"><<a href="mailto:cfe-dev@lists.llvm.org" class="gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br class="gmail_msg">
<br class="gmail_msg">
I have been working on fixing [1]. To me it is not obvious what is the<br class="gmail_msg">
proper solution is. Maybe someone has an idea?<br class="gmail_msg">
<br class="gmail_msg">
Consider this small test program:<br class="gmail_msg">
<br class="gmail_msg">
template <class T><br class="gmail_msg">
void Function(T) {<br class="gmail_msg">
struct Struct {<br class="gmail_msg">
typedef int Something;<br class="gmail_msg">
Something x;<br class="gmail_msg">
};<br class="gmail_msg">
}<br class="gmail_msg">
void test() { Function('c'); }<br class="gmail_msg">
<br class="gmail_msg">
Compiling it with -Wall -fsyntax-only generates the warning about the<br class="gmail_msg">
local typedef being unused.<br class="gmail_msg">
<br class="gmail_msg">
When adding -ast-dump one can see that there are two TypedefDecls, one<br class="gmail_msg">
for the FunctionTemplateDecl and another for the one instantiation of<br class="gmail_msg">
the template. The same thing applies when the typedef is dependent on a<br class="gmail_msg">
template parameter, say "typedef T Something" in this case.<br class="gmail_msg">
<br class="gmail_msg">
I observed this behaviour:<br class="gmail_msg">
<br class="gmail_msg">
When the typedef is independent, then neither of the TypedefDecls will<br class="gmail_msg">
be marked referenced as of now. Additionally, the type of ValueDecls<br class="gmail_msg">
like "Something x;" has the non-templated typedef as its declaration.<br class="gmail_msg">
<br class="gmail_msg">
When the typedef is dependent, then only the non-templated TypedefDecl<br class="gmail_msg">
will be marked referenced. The type of ValueDecls does naturally refer<br class="gmail_msg">
to the instantiated TypedefDecl.<br class="gmail_msg">
<br class="gmail_msg">
Is it supposed to be that way?<br class="gmail_msg">
<br class="gmail_msg">
If the types of declarations always referred to the instantiated<br class="gmail_msg">
typedefs, it would be straightforward to fix by traversing all<br class="gmail_msg">
declarations and marking the typedefs of their types referenced.<br class="gmail_msg">
<br class="gmail_msg">
Alternatively, it would be possible to only check non-instantiated<br class="gmail_msg">
types on being referenced. Actually, this might to be the simplest one..<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
Johannes<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
[1] <a href="https://bugs.llvm.org/show_bug.cgi?id=24883" rel="noreferrer" class="gmail_msg" target="_blank">https://bugs.llvm.org/show_bug.cgi?id=24883</a><br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
cfe-dev mailing list<br class="gmail_msg">
<a href="mailto:cfe-dev@lists.llvm.org" class="gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br class="gmail_msg">
</blockquote></div><br class="gmail_msg"></div>
_______________________________________________<br class="gmail_msg">
cfe-dev mailing list<br class="gmail_msg">
<a href="mailto:cfe-dev@lists.llvm.org" class="gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br class="gmail_msg">
</blockquote></div>