From ef9d09c4699a2a61d6f28b59b7583b2b28c0a531 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 3 Jan 2011 19:27:19 +0000 Subject: [PATCH] Fix PR8841 by checking for both semantic and lecical dependent contexts. This prevents -Wunused-function from firing on friend function definitions inside of class templates for example. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122763 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 3 ++- test/SemaCXX/warn-unused-filescoped.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 32791f9f98..dc851a3e83 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -557,7 +557,8 @@ bool Sema::ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const { return false; // Ignore class templates. - if (D->getDeclContext()->isDependentContext()) + if (D->getDeclContext()->isDependentContext() || + D->getLexicalDeclContext()->isDependentContext()) return false; if (const FunctionDecl *FD = dyn_cast(D)) { diff --git a/test/SemaCXX/warn-unused-filescoped.cpp b/test/SemaCXX/warn-unused-filescoped.cpp index 75fc6a4da0..628075ac04 100644 --- a/test/SemaCXX/warn-unused-filescoped.cpp +++ b/test/SemaCXX/warn-unused-filescoped.cpp @@ -54,3 +54,19 @@ namespace { }; template <> int TS2::x; // expected-warning{{unused}} } + +namespace PR8841 { + // Ensure that friends of class templates are considered to have a dependent + // context and not marked unused. + namespace { + template struct X { + friend bool operator==(const X&, const X&) { return false; } + }; + } + template void template_test(X x) { + (void)(x == x); + } + void test(X x) { + template_test(x); + } +} -- 2.40.0