]> granicus.if.org Git - clang/commitdiff
Do not warn with -Wuninitialized when the member is used in a sizeof or address-of...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 21 Sep 2010 10:47:20 +0000 (10:47 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 21 Sep 2010 10:47:20 +0000 (10:47 +0000)
Fixes rdar://8331312.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114426 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/constructor-initializer.cpp

index 4efb62a9d40b150bb3dacfb30e9f74f89e1cabfe..00f71a2bd46e4b075554a8abb4654712b7f59e0f 100644 (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) {
index 31d53302bf4727275e4f9f9b7cd40930ab01dc36..a74fbe1800e2c04442c4e4124721046c2ef4c8a7 100644 (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 {