[cfe-commits] r118500 - in /cfe/trunk: lib/Sema/SemaAttr.cpp test/SemaCXX/warn-unused-variables.cpp

Douglas Gregor dgregor at apple.com
Tue Nov 9 06:57:47 PST 2010


Author: dgregor
Date: Tue Nov  9 08:57:47 2010
New Revision: 118500

URL: http://llvm.org/viewvc/llvm-project?rev=118500&view=rev
Log:
Make #pragma unused work for static local variables.

Modified:
    cfe/trunk/lib/Sema/SemaAttr.cpp
    cfe/trunk/test/SemaCXX/warn-unused-variables.cpp

Modified: cfe/trunk/lib/Sema/SemaAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=118500&r1=118499&r2=118500&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAttr.cpp Tue Nov  9 08:57:47 2010
@@ -282,7 +282,7 @@
     }
 
     VarDecl *VD = Lookup.getAsSingle<VarDecl>();
-    if (!VD || !VD->hasLocalStorage()) {
+    if (!VD || !(VD->hasLocalStorage() || VD->isStaticLocal())) {
       Diag(PragmaLoc, diag::warn_pragma_unused_expected_localvar)
         << Name << SourceRange(Tok.getLocation());
       continue;

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=118500&r1=118499&r2=118500&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unused-variables.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-variables.cpp Tue Nov  9 08:57:47 2010
@@ -59,3 +59,9 @@
     X<char> str (read_from_file()); // expected-error{{use of undeclared identifier 'read_from_file'}}
   }
 }
+
+void unused_local_static() {
+  static int x = 0;
+  static int y = 0; // expected-warning{{unused variable 'y'}}
+#pragma unused(x)
+}





More information about the cfe-commits mailing list