diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-04-19 23:56:20 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-04-19 23:56:20 +0000 |
commit | c077e45fa9395c4fd97d8a43c708ee07f982fe2c (patch) | |
tree | 74c9ea708d0adcf9cc40fa97888f70064ac4070b | |
parent | 16573fa9705b546b7597c273b25b85d6321e2b33 (diff) |
Do not diagnose unused-parameter errors in template instantiations. We
will already have done so when the template is declared.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101838 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/Sema.h | 8 | ||||
-rw-r--r-- | test/SemaCXX/warn-unused-parameters.cpp | 26 |
2 files changed, 33 insertions, 1 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index a95d08262e..0535923d6b 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -853,12 +853,18 @@ public: if (Diags.getDiagnosticLevel(diag::warn_unused_parameter) == Diagnostic::Ignored) return; + + // Don't diagnose unused-parameter errors in template instantiations; we + // will already have done so in the template itself. + if (!ActiveTemplateInstantiations.empty()) + return; for (; Param != ParamEnd; ++Param) { if (!(*Param)->isUsed() && (*Param)->getDeclName() && - !(*Param)->template hasAttr<UnusedAttr>()) + !(*Param)->template hasAttr<UnusedAttr>()) { Diag((*Param)->getLocation(), diag::warn_unused_parameter) << (*Param)->getDeclName(); + } } } diff --git a/test/SemaCXX/warn-unused-parameters.cpp b/test/SemaCXX/warn-unused-parameters.cpp new file mode 100644 index 0000000000..75d8dcc549 --- /dev/null +++ b/test/SemaCXX/warn-unused-parameters.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -fsyntax-only -Wunused-parameter -verify %s +template<typename T> +struct X { + T f0(T x); + T f1(T x); + T f2(T); + template<typename U> U f3(U x); + template<typename U> U f4(U x); + template<typename U> U f5(U); +}; + +template<typename T> T X<T>::f0(T x) { return x; } +template<typename T> T X<T>::f1(T) { return T(); } +template<typename T> T X<T>::f2(T x) { return T(); } // expected-warning{{unused parameter 'x'}} +template<typename T> template<typename U> U X<T>::f3(U x) { return x; } +template<typename T> template<typename U> U X<T>::f4(U) { return U(); } +template<typename T> template<typename U> U X<T>::f5(U x) { return U(); } // expected-warning{{unused parameter 'x'}} + +void test_X(X<int> &x, int i) { + x.f0(i); + x.f1(i); + x.f2(i); + x.f3(i); + x.f4(i); + x.f5(i); +} |