зеркало из https://github.com/microsoft/clang-1.git
Don't emit 'dead initialization' warnings for variables marked 'unused'.
This fixes PR 2573: http://llvm.org/bugs/show_bug.cgi?id=2573 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54009 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
7379889275
Коммит
fc7ff55404
|
@ -164,11 +164,16 @@ public:
|
|||
for (ScopedDecl* SD = DS->getDecl(); SD; SD = SD->getNextDeclarator()) {
|
||||
|
||||
VarDecl* V = dyn_cast<VarDecl>(SD);
|
||||
if (!V) continue;
|
||||
|
||||
if (!V)
|
||||
continue;
|
||||
|
||||
if (V->hasLocalStorage())
|
||||
if (Expr* E = V->getInit())
|
||||
if (!Live(V, AD)) {
|
||||
if (Expr* E = V->getInit()) {
|
||||
// A dead initialization is a variable that is dead after it
|
||||
// is initialized. We don't flag warnings for those variables
|
||||
// marked 'unused'.
|
||||
if (!Live(V, AD) && V->getAttr<UnusedAttr>() == 0) {
|
||||
// Special case: check for initializations with constants.
|
||||
//
|
||||
// e.g. : int x = 0;
|
||||
|
@ -179,6 +184,7 @@ public:
|
|||
if (!E->isConstantExpr(Ctx,NULL))
|
||||
Report(V, DeadInit, V->getLocation(), E->getSourceRange());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -77,5 +77,12 @@ int f11() {
|
|||
return ++x; // expected-warning{{never read}}
|
||||
}
|
||||
|
||||
|
||||
int f12a(int y) {
|
||||
int x = y; // expected-warning{{never read}}
|
||||
return 1;
|
||||
}
|
||||
int f12b(int y) {
|
||||
int x __attribute__((unused)) = y; // no-warning
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче