]> granicus.if.org Git - clang/commitdiff
Make #pragma unused work for static local variables.
authorDouglas Gregor <dgregor@apple.com>
Tue, 9 Nov 2010 14:57:47 +0000 (14:57 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 9 Nov 2010 14:57:47 +0000 (14:57 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118500 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaAttr.cpp
test/SemaCXX/warn-unused-variables.cpp

index d7290c3089af52f9e067c1b1a538cda2422de82e..02b8289022c0ce26c2e793a3c6fd698e228abc51 100644 (file)
@@ -282,7 +282,7 @@ void Sema::ActOnPragmaUnused(const Token *Identifiers, unsigned NumIdentifiers,
     }
 
     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;
index 6992cdcd0902a73299de5f4f005d3c4d152eef44..8ae7d6ace4daa737154d9098b8f9d533376b94e5 100644 (file)
@@ -59,3 +59,9 @@ namespace PR6948 {
     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)
+}