diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-11-09 14:57:47 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-11-09 14:57:47 +0000 |
commit | 268f89e02de7bddbc9d7d7a147a3003bd81cf0d7 (patch) | |
tree | e996cbbe2c2d6e030138cb9009de7ebae4eb02f2 | |
parent | 0b9c22b61a3c99c8c0e8d898adb0f60afa76584e (diff) |
Make #pragma unused work for static local variables.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118500 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaAttr.cpp | 2 | ||||
-rw-r--r-- | test/SemaCXX/warn-unused-variables.cpp | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/lib/Sema/SemaAttr.cpp b/lib/Sema/SemaAttr.cpp index d7290c3089..02b8289022 100644 --- a/lib/Sema/SemaAttr.cpp +++ b/lib/Sema/SemaAttr.cpp @@ -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; diff --git a/test/SemaCXX/warn-unused-variables.cpp b/test/SemaCXX/warn-unused-variables.cpp index 6992cdcd09..8ae7d6ace4 100644 --- a/test/SemaCXX/warn-unused-variables.cpp +++ b/test/SemaCXX/warn-unused-variables.cpp @@ -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) +} |