From baa76376646475f8e0b816a2142cb794bfc1a02c Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Sat, 11 Oct 2014 00:24:15 +0000 Subject: [PATCH] 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219551 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/Sema.cpp | 7 ++++++- .../warn-unused-private-field-delayed-template.cpp | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/SemaCXX/warn-unused-private-field-delayed-template.cpp diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 7ecd41697d..aae2008957 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -545,7 +545,12 @@ static bool MethodsAndNestedClassesComplete(const CXXRecordDecl *RD, if (const CXXMethodDecl *M = dyn_cast(*I)) Complete = M->isDefined() || (M->isPure() && !isa(M)); else if (const FunctionTemplateDecl *F = dyn_cast(*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(*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 index 0000000000..7cafcca643 --- /dev/null +++ b/test/SemaCXX/warn-unused-private-field-delayed-template.cpp @@ -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 + void f() { + x = 0; + } +}; -- 2.40.0