summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2017-01-28 01:50:33 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2017-01-28 01:50:33 +0000
commitcfa5dc4a1dc2b7495aba96caba6fd2600c1ceb8a (patch)
tree6de36cd2e83839ab9291952ae5603dafb9cbc621
parentae6b8b69332f3001a61c34d8bbfa4c23e69f747d (diff)
downloadbcm5719-llvm-cfa5dc4a1dc2b7495aba96caba6fd2600c1ceb8a.tar.gz
bcm5719-llvm-cfa5dc4a1dc2b7495aba96caba6fd2600c1ceb8a.zip
-Wunused-func-template: do not warn on non-template function declarations that
were nonetheless instantiated (particularly, non-template friends declared within class templates). llvm-svn: 293358
-rw-r--r--clang/lib/Sema/SemaTemplateInstantiateDecl.cpp7
-rw-r--r--clang/test/SemaTemplate/undefined-template.cpp8
2 files changed, 14 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 48d8b94af15..ed91057c472 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3726,7 +3726,12 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
PendingInstantiations.push_back(
std::make_pair(Function, PointOfInstantiation));
} else if (TSK == TSK_ImplicitInstantiation) {
- if (AtEndOfTU && !getDiagnostics().hasErrorOccurred()) {
+ if (AtEndOfTU && !getDiagnostics().hasErrorOccurred() &&
+ // A non-template function that is only lexically in a dependent
+ // context, such as a friend function in a class template, should
+ // not produce a warning.
+ (PatternDecl->getDescribedFunctionTemplate() ||
+ PatternDecl->getDeclContext()->isDependentContext())) {
Diag(PointOfInstantiation, diag::warn_func_template_missing)
<< Function;
Diag(PatternDecl->getLocation(), diag::note_forward_template_decl);
diff --git a/clang/test/SemaTemplate/undefined-template.cpp b/clang/test/SemaTemplate/undefined-template.cpp
index a03d0b7cff6..7dfe2fde94b 100644
--- a/clang/test/SemaTemplate/undefined-template.cpp
+++ b/clang/test/SemaTemplate/undefined-template.cpp
@@ -134,6 +134,14 @@ void func_23(C1<int>::C2<long> *x) {
// expected-note@-1{{add an explicit instantiation declaration to suppress this warning if 'C1<int>::C2<long>::tmeth_2<int>' is explicitly instantiated in another translation unit}}
}
+namespace test_24 {
+ template <typename T> struct X {
+ friend void g(int);
+ operator int() { return 0; }
+ };
+ void h(X<int> x) { g(x); } // no warning for use of 'g' despite the declaration having been instantiated from a template
+}
+
int main() {
return 0;
}
OpenPOWER on IntegriCloud