]> granicus.if.org Git - clang/commitdiff
For global record types, the self reference checker was called twice, resulting
authorRichard Trieu <rtrieu@google.com>
Mon, 6 Aug 2012 21:09:23 +0000 (21:09 +0000)
committerRichard Trieu <rtrieu@google.com>
Mon, 6 Aug 2012 21:09:23 +0000 (21:09 +0000)
in duplicate -Wuninitialized warnings.  Change so that only the check in
TryConstructorInitialization() will be used and a single warning be emitted.

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

lib/Sema/SemaDecl.cpp
test/SemaCXX/uninitialized.cpp

index c1086fbe14263954ec9d73c845ca8dce7f3fa278..a512c0364c72f3da7409998015070fcf9a91b565 100644 (file)
@@ -6310,7 +6310,10 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init,
   // Check for self-references within variable initializers.
   // Variables declared within a function/method body are handled
   // by a dataflow analysis.
-  if (!VDecl->hasLocalStorage() && !VDecl->isStaticLocal())
+  // Record types initialized by initializer list are handled here.
+  // Initialization by constructors are handled in TryConstructorInitialization.
+  if (!VDecl->hasLocalStorage() && !VDecl->isStaticLocal() &&
+      (isa<InitListExpr>(Init) || !VDecl->getType()->isRecordType()))
     CheckSelfReference(RealDecl, Init);
 
   ParenListExpr *CXXDirectInit = dyn_cast<ParenListExpr>(Init);
index e8272362310536babc3a726d1d9abf42cdf4fb64..13d287bf1af60ff72d1c51afe7a8250a0bb60212 100644 (file)
@@ -116,6 +116,29 @@ void setupA(bool x) {
   A a19 = getA(x ? a19 : a17);  // expected-warning {{variable 'a19' is uninitialized when used within its own initialization}}
 }
 
+bool x;
+
+A a1;
+A a2(a1.get());
+A a3(a1);
+A a4(&a4);
+A a5(a5.zero());
+A a6(a6.ONE);
+A a7 = getA();
+A a8 = getA(a8.TWO);
+A a9 = getA(&a9);
+A a10(a10.count);
+
+A a11(a11);  // expected-warning {{variable 'a11' is uninitialized when used within its own initialization}}
+A a12(a12.get());  // expected-warning {{variable 'a12' is uninitialized when used within its own initialization}}
+A a13(a13.num);  // expected-warning {{variable 'a13' is uninitialized when used within its own initialization}}
+A a14 = A(a14);  // expected-warning {{variable 'a14' is uninitialized when used within its own initialization}}
+A a15 = getA(a15.num);  // expected-warning {{variable 'a15' is uninitialized when used within its own initialization}}
+A a16(&a16.num);  // expected-warning {{variable 'a16' is uninitialized when used within its own initialization}}
+A a17(a17.get2());  // expected-warning {{variable 'a17' is uninitialized when used within its own initialization}}
+A a18 = x ? a18 : a17;  // expected-warning {{variable 'a18' is uninitialized when used within its own initialization}}
+A a19 = getA(x ? a19 : a17);  // expected-warning {{variable 'a19' is uninitialized when used within its own initialization}}
+
 struct B {
   // POD struct.
   int x;