Skip to content

Commit ba57154

Browse files
committed
Make #pragma unused work for static local variables.
llvm-svn: 118500
1 parent 82f755c commit ba57154

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

clang/lib/Sema/SemaAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ void Sema::ActOnPragmaUnused(const Token *Identifiers, unsigned NumIdentifiers,
282282
}
283283

284284
VarDecl *VD = Lookup.getAsSingle<VarDecl>();
285-
if (!VD || !VD->hasLocalStorage()) {
285+
if (!VD || !(VD->hasLocalStorage() || VD->isStaticLocal())) {
286286
Diag(PragmaLoc, diag::warn_pragma_unused_expected_localvar)
287287
<< Name << SourceRange(Tok.getLocation());
288288
continue;

clang/test/SemaCXX/warn-unused-variables.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,9 @@ namespace PR6948 {
5959
X<char> str (read_from_file()); // expected-error{{use of undeclared identifier 'read_from_file'}}
6060
}
6161
}
62+
63+
void unused_local_static() {
64+
static int x = 0;
65+
static int y = 0; // expected-warning{{unused variable 'y'}}
66+
#pragma unused(x)
67+
}

0 commit comments

Comments
 (0)