[PATCH] clang-cl: Don't warn for unused private fields when encountering a late parsed template member

Hans Wennborg hans at chromium.org
Fri Oct 10 17:18:31 PDT 2014


================
Comment at: lib/Sema/Sema.cpp:548
@@ -547,2 +547,3 @@
     else if (const FunctionTemplateDecl *F = dyn_cast<FunctionTemplateDecl>(*I))
-      Complete = F->getTemplatedDecl()->isDefined();
+      Complete = !F->getTemplatedDecl()->isLateTemplateParsed() &&
+                  F->getTemplatedDecl()->isDefined();
----------------
ehsan wrote:
> hans wrote:
> > Is the issue that the template has been defined, but we haven't parsed and semantically analysed it because it's late-parsed?
> > 
> > This gets called from ActOnEndOfTranslationUnit, so shouldn't the delayed template parsing already have taken place?
> Yes the template is not defined by we haven't done semantic analysis (and parsing!) on it yet.  It looks like by ActOnEndOfTranslationUnit the semantic analysis still wouldn't happen unless if we see a call to that function (or presumably other things such as its address being taken etc.)  IOW if the test case includes an instantiation of the template member, the warning doesn't appear.
Oh that makes sense. If we don't instantiate it, we don't parse it.

This patch seems correct to me, but please add a comment about this check.

http://reviews.llvm.org/D5718






More information about the cfe-commits mailing list