]> granicus.if.org Git - clang/commitdiff
Don't warn about address-to-member used as part of initialisation, if
authorJoerg Sonnenberger <joerg@bec.de>
Sun, 17 Jun 2012 23:10:39 +0000 (23:10 +0000)
committerJoerg Sonnenberger <joerg@bec.de>
Sun, 17 Jun 2012 23:10:39 +0000 (23:10 +0000)
the member expression is in parentheses.

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

lib/Sema/SemaDecl.cpp
test/Sema/uninit-variables.c

index d98ce6b0a6cdbf525c5e0720a507e84559e25b40..63385ccd196afa118246e6b96398f34154f3305e 100644 (file)
@@ -6232,7 +6232,7 @@ namespace {
     void VisitUnaryOperator(UnaryOperator *E) {
       // For POD record types, addresses of its own members are well-defined.
       if (E->getOpcode() == UO_AddrOf && isRecordType && isPODType &&
-          isa<MemberExpr>(E->getSubExpr())) return;
+          isa<MemberExpr>(E->getSubExpr()->IgnoreParens())) return;
       Inherited::VisitUnaryOperator(E);
     } 
 
index 180d60cbce7631f0ff0a3a2632dec24cfb5d3867..59577b958537ace142af6226f36d0be1d9826959 100644 (file)
@@ -438,6 +438,10 @@ void test54() {
   ASSIGN(int, c, d);  // expected-warning {{variable 'c' is uninitialized when used here}}
 }
 
+// Taking the address is fine
+struct { struct { void *p; } a; } test55 = { { &test55.a }}; // no-warning
+struct { struct { void *p; } a; } test56 = { { &(test56.a) }}; // no-warning
+
 void uninit_in_loop() {
   int produce(void);
   void consume(int);