Do not warn with -Wuninitialized when the member is used in a sizeof or address-of expression.

Fixes rdar://8331312.

llvm-svn: 114426
This commit is contained in:
Argyrios Kyrtzidis 2010-09-21 10:47:20 +00:00
parent a35499e2af
commit 03f0e2b5b4
2 changed files with 13 additions and 1 deletions

View File

@ -1246,6 +1246,14 @@ static bool InitExprContainsUninitializedFields(const Stmt *S,
*L = ME->getMemberLoc();
return true;
}
} else if (isa<SizeOfAlignOfExpr>(S)) {
// sizeof/alignof doesn't reference contents, do not warn.
return false;
} else if (const UnaryOperator *UOE = dyn_cast<UnaryOperator>(S)) {
// address-of doesn't reference contents (the pointer may be dereferenced
// in the same expression but it would be rare; and weird).
if (UOE->getOpcode() == UO_AddrOf)
return false;
}
for (Stmt::const_child_iterator it = S->child_begin(), e = S->child_end();
it != e; ++it) {

View File

@ -144,9 +144,13 @@ int IntWrapper(int i) { return 0; };
class InitializeUsingSelfExceptions {
int A;
int B;
int C;
void *P;
InitializeUsingSelfExceptions(int B)
: A(IntWrapper(A)), // Due to a conservative implementation, we do not report warnings inside function/ctor calls even though it is possible to do so.
B(B) {} // Not a warning; B is a local variable.
B(B), // Not a warning; B is a local variable.
C(sizeof(C)), // sizeof doesn't reference contents, do not warn
P(&P) {} // address-of doesn't reference contents (the pointer may be dereferenced in the same expression but it would be rare; and weird)
};
class CopyConstructorTest {