[cfe-commits] r161345 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/uninitialized.cpp
Richard Trieu
rtrieu at google.com
Mon Aug 6 14:09:23 PDT 2012
Author: rtrieu
Date: Mon Aug 6 16:09:23 2012
New Revision: 161345
URL: http://llvm.org/viewvc/llvm-project?rev=161345&view=rev
Log:
For global record types, the self reference checker was called twice, resulting
in duplicate -Wuninitialized warnings. Change so that only the check in
TryConstructorInitialization() will be used and a single warning be emitted.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/uninitialized.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=161345&r1=161344&r2=161345&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Aug 6 16:09:23 2012
@@ -6310,7 +6310,10 @@
// 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);
Modified: cfe/trunk/test/SemaCXX/uninitialized.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninitialized.cpp?rev=161345&r1=161344&r2=161345&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/uninitialized.cpp (original)
+++ cfe/trunk/test/SemaCXX/uninitialized.cpp Mon Aug 6 16:09:23 2012
@@ -116,6 +116,29 @@
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;
More information about the cfe-commits
mailing list