[cfe-commits] r133580 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaCXX/for-range-unused.cpp test/SemaCXX/warn-unused-variables.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Tue Jun 21 16:42:09 PDT 2011
Author: rsmith
Date: Tue Jun 21 18:42:09 2011
New Revision: 133580
URL: http://llvm.org/viewvc/llvm-project?rev=133580&view=rev
Log:
Fix PR10168: don't warn for unused non-dependent variables in both the template definition and each instantiation.
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/SemaCXX/for-range-unused.cpp
cfe/trunk/test/SemaCXX/warn-unused-variables.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=133580&r1=133579&r2=133580&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Tue Jun 21 18:42:09 2011
@@ -415,8 +415,10 @@
!Var->isCXXForRangeDecl())
SemaRef.ActOnUninitializedDecl(Var, false);
- // Diagnose unused local variables.
- if (!Var->isInvalidDecl() && Owner->isFunctionOrMethod() && !Var->isUsed())
+ // Diagnose unused local variables with dependent types, where the diagnostic
+ // will have been deferred.
+ if (!Var->isInvalidDecl() && Owner->isFunctionOrMethod() && !Var->isUsed() &&
+ D->getType()->isDependentType())
SemaRef.DiagnoseUnusedDecl(Var);
return Var;
Modified: cfe/trunk/test/SemaCXX/for-range-unused.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/for-range-unused.cpp?rev=133580&r1=133579&r2=133580&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/for-range-unused.cpp (original)
+++ cfe/trunk/test/SemaCXX/for-range-unused.cpp Tue Jun 21 18:42:09 2011
@@ -5,8 +5,7 @@
template <typename T>
struct Vector {
void doIt() {
- // FIXME: PR10168: Only warn once for this!
- int a; // expected-warning 2{{unused variable 'a'}}
+ int a; // expected-warning {{unused variable 'a'}}
for (auto& e : elements)
;
@@ -18,5 +17,5 @@
int main(int, char**) {
Vector<int> vector;
- vector.doIt(); // expected-note {{requested here}}
+ vector.doIt();
}
Modified: cfe/trunk/test/SemaCXX/warn-unused-variables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-variables.cpp?rev=133580&r1=133579&r2=133580&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unused-variables.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-variables.cpp Tue Jun 21 18:42:09 2011
@@ -54,3 +54,29 @@
static int y = 0; // expected-warning{{unused variable 'y'}}
#pragma unused(x)
}
+
+// PR10168
+namespace PR10168 {
+ // We expect a warning in the definition only for non-dependent variables, and
+ // a warning in the instantiation only for dependent variables.
+ template<typename T>
+ struct S {
+ void f() {
+ int a; // expected-warning {{unused variable 'a'}}
+ T b; // expected-warning 2{{unused variable 'b'}}
+ }
+ };
+
+ template<typename T>
+ void f() {
+ int a; // expected-warning {{unused variable 'a'}}
+ T b; // expected-warning 2{{unused variable 'b'}}
+ }
+
+ void g() {
+ S<int>().f(); // expected-note {{here}}
+ S<char>().f(); // expected-note {{here}}
+ f<int>(); // expected-note {{here}}
+ f<char>(); // expected-note {{here}}
+ }
+}
More information about the cfe-commits
mailing list