]> granicus.if.org Git - clang/commitdiff
clang-cl: Don't warn for unused private fields when encountering a late parsed templa...
authorEhsan Akhgari <ehsan.akhgari@gmail.com>
Sat, 11 Oct 2014 00:24:15 +0000 (00:24 +0000)
committerEhsan Akhgari <ehsan.akhgari@gmail.com>
Sat, 11 Oct 2014 00:24:15 +0000 (00:24 +0000)
Summary: This fixes PR21235.

Test Plan: Includes an automated test.

Reviewers: hansw

Subscribers: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219551 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.cpp
test/SemaCXX/warn-unused-private-field-delayed-template.cpp [new file with mode: 0644]

index 7ecd41697d6ff5f5c7468460b57ef0e2c0aeea7d..aae2008957ef26aa599099b87471272505f2d4c2 100644 (file)
@@ -545,7 +545,12 @@ static bool MethodsAndNestedClassesComplete(const CXXRecordDecl *RD,
     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;
diff --git a/test/SemaCXX/warn-unused-private-field-delayed-template.cpp b/test/SemaCXX/warn-unused-private-field-delayed-template.cpp
new file mode 100644 (file)
index 0000000..7cafcca
--- /dev/null
@@ -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;
+  }
+};