r293358 - -Wunused-func-template: do not warn on non-template function declarations that
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 27 17:50:33 PST 2017
Author: rsmith
Date: Fri Jan 27 19:50:33 2017
New Revision: 293358
URL: http://llvm.org/viewvc/llvm-project?rev=293358&view=rev
Log:
-Wunused-func-template: do not warn on non-template function declarations that
were nonetheless instantiated (particularly, non-template friends declared
within class templates).
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/SemaTemplate/undefined-template.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=293358&r1=293357&r2=293358&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri Jan 27 19:50:33 2017
@@ -3726,7 +3726,12 @@ void Sema::InstantiateFunctionDefinition
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);
Modified: cfe/trunk/test/SemaTemplate/undefined-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/undefined-template.cpp?rev=293358&r1=293357&r2=293358&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/undefined-template.cpp (original)
+++ cfe/trunk/test/SemaTemplate/undefined-template.cpp Fri Jan 27 19:50:33 2017
@@ -134,6 +134,14 @@ void func_23(C1<int>::C2<long> *x) {
// expected-note at -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;
}
More information about the cfe-commits
mailing list