forked from OSchip/llvm-project
-Wuninitialized: warn about uninitialized values resulting from ?: that evaluate to lvalues (in C++).
llvm-svn: 172875
This commit is contained in:
parent
ac6cfa41d6
commit
7ba78c679c
|
@ -358,6 +358,16 @@ static const DeclRefExpr *getSelfInitExpr(VarDecl *VD) {
|
|||
}
|
||||
|
||||
void ClassifyRefs::classify(const Expr *E, Class C) {
|
||||
// The result of a ?: could also be an lvalue.
|
||||
E = E->IgnoreParens();
|
||||
if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E)) {
|
||||
const Expr *TrueExpr = CO->getTrueExpr();
|
||||
if (!isa<OpaqueValueExpr>(TrueExpr))
|
||||
classify(TrueExpr, C);
|
||||
classify(CO->getFalseExpr(), C);
|
||||
return;
|
||||
}
|
||||
|
||||
FindVarResult Var = findVar(E, DC);
|
||||
if (const DeclRefExpr *DRE = Var.getDeclRefExpr())
|
||||
Classification[DRE] = std::max(Classification[DRE], C);
|
||||
|
|
|
@ -41,8 +41,8 @@ void test_stuff () {
|
|||
int j = far(j);
|
||||
int k = __alignof__(k);
|
||||
|
||||
int l = k ? l : l; // FIXME: warn here
|
||||
int m = 1 + (k ? m : m); // FIXME: warn here
|
||||
int l = k ? l : l; // expected-warning {{variable 'l' is uninitialized when used within its own initialization}}
|
||||
int m = 1 + (k ? m : m); // expected-warning {{'m' is uninitialized when used within its own initialization}}
|
||||
int n = -n; // expected-warning {{variable 'n' is uninitialized when used within its own initialization}}
|
||||
|
||||
for (;;) {
|
||||
|
@ -61,8 +61,8 @@ void test_stuff () {
|
|||
int j = far(j);
|
||||
int k = __alignof__(k);
|
||||
|
||||
int l = k ? l : l; // FIXME: warn here
|
||||
int m = 1 + (k ? m : m); // FIXME: warn here
|
||||
int l = k ? l : l; // expected-warning {{variable 'l' is uninitialized when used within its own initialization}}
|
||||
int m = 1 + (k ? m : m); // expected-warning {{'m' is uninitialized when used within its own initialization}}
|
||||
int n = -n; // expected-warning {{variable 'n' is uninitialized when used within its own initialization}}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue