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

Ehsan Akhgari ehsan.akhgari at gmail.com
Fri Oct 10 17:24:15 PDT 2014


Author: ehsan
Date: Fri Oct 10 19:24:15 2014
New Revision: 219551

URL: http://llvm.org/viewvc/llvm-project?rev=219551&view=rev
Log:
clang-cl: Don't warn for unused private fields when encountering a late parsed template member

Summary: This fixes PR21235.

Test Plan: Includes an automated test.

Reviewers: hansw

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D5718

Added:
    cfe/trunk/test/SemaCXX/warn-unused-private-field-delayed-template.cpp
Modified:
    cfe/trunk/lib/Sema/Sema.cpp

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=219551&r1=219550&r2=219551&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Fri Oct 10 19:24:15 2014
@@ -545,7 +545,12 @@ static bool MethodsAndNestedClassesCompl
     if (const CXXMethodDecl *M = dyn_cast<CXXMethodDecl>(*I))
       Complete = M->isDefined() || (M->isPure() && !isa<CXXDestructorDecl>(M));
     else if (const FunctionTemplateDecl *F = dyn_cast<FunctionTemplateDecl>(*I))
-      Complete = F->getTemplatedDecl()->isDefined();
+      // If the template function is marked as late template parsed at this point,
+      // it has not been instantiated and therefore we have not performed semantic
+      // analysis on it yet, so we cannot know if the type can be considered
+      // complete.
+      Complete = !F->getTemplatedDecl()->isLateTemplateParsed() &&
+                  F->getTemplatedDecl()->isDefined();
     else if (const CXXRecordDecl *R = dyn_cast<CXXRecordDecl>(*I)) {
       if (R->isInjectedClassName())
         continue;

Added: cfe/trunk/test/SemaCXX/warn-unused-private-field-delayed-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-private-field-delayed-template.cpp?rev=219551&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unused-private-field-delayed-template.cpp (added)
+++ cfe/trunk/test/SemaCXX/warn-unused-private-field-delayed-template.cpp Fri Oct 10 19:24:15 2014
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -fdelayed-template-parsing -Wunused-private-field -Wused-but-marked-unused -Wno-uninitialized -verify -std=c++11 %s
+// expected-no-diagnostics
+
+class EverythingMayBeUsed {
+  int x;
+public:
+  template <class T>
+  void f() {
+    x = 0;
+  }
+};





More information about the cfe-commits mailing list