diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 3 | ||||
| -rw-r--r-- | clang/test/SemaCXX/warn-unused-filescoped.cpp | 16 |
2 files changed, 18 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 32791f9f983..dc851a3e836 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/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<FunctionDecl>(D)) { diff --git a/clang/test/SemaCXX/warn-unused-filescoped.cpp b/clang/test/SemaCXX/warn-unused-filescoped.cpp index 75fc6a4da0b..628075ac04d 100644 --- a/clang/test/SemaCXX/warn-unused-filescoped.cpp +++ b/clang/test/SemaCXX/warn-unused-filescoped.cpp @@ -54,3 +54,19 @@ namespace { }; template <> int TS2<int>::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 <typename T> struct X { + friend bool operator==(const X&, const X&) { return false; } + }; + } + template <typename T> void template_test(X<T> x) { + (void)(x == x); + } + void test(X<int> x) { + template_test(x); + } +} |

