[cfe-commits] r114426 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/SemaCXX/constructor-initializer.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Sep 21 03:47:21 PDT 2010


Author: akirtzidis
Date: Tue Sep 21 05:47:20 2010
New Revision: 114426

URL: http://llvm.org/viewvc/llvm-project?rev=114426&view=rev
Log:
Do not warn with -Wuninitialized when the member is used in a sizeof or address-of expression.
Fixes rdar://8331312.

Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/SemaCXX/constructor-initializer.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=114426&r1=114425&r2=114426&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Sep 21 05:47:20 2010
@@ -1246,6 +1246,14 @@
       *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) {

Modified: cfe/trunk/test/SemaCXX/constructor-initializer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constructor-initializer.cpp?rev=114426&r1=114425&r2=114426&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constructor-initializer.cpp (original)
+++ cfe/trunk/test/SemaCXX/constructor-initializer.cpp Tue Sep 21 05:47:20 2010
@@ -144,9 +144,13 @@
 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 {





More information about the cfe-commits mailing list