diff options
author | dim <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
commit | 056abd2059c65a3e908193aeae16fad98017437c (patch) | |
tree | 2732d02d7d51218d6eed98ac7fcfc5b8794896b5 /test/SemaCXX/uninitialized.cpp | |
parent | cc73504950eb7b5dff2dded9bedd67bc36d64641 (diff) | |
download | FreeBSD-src-056abd2059c65a3e908193aeae16fad98017437c.zip FreeBSD-src-056abd2059c65a3e908193aeae16fad98017437c.tar.gz |
Vendor import of clang release_32 branch r168974 (effectively, 3.2 RC2):
http://llvm.org/svn/llvm-project/cfe/branches/release_32@168974
Diffstat (limited to 'test/SemaCXX/uninitialized.cpp')
-rw-r--r-- | test/SemaCXX/uninitialized.cpp | 151 |
1 files changed, 125 insertions, 26 deletions
diff --git a/test/SemaCXX/uninitialized.cpp b/test/SemaCXX/uninitialized.cpp index 385548b..f55f10f 100644 --- a/test/SemaCXX/uninitialized.cpp +++ b/test/SemaCXX/uninitialized.cpp @@ -114,6 +114,19 @@ void setupA(bool x) { 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}} + A a20{a20}; // expected-warning {{variable 'a20' is uninitialized when used within its own initialization}} + A a21 = {a21}; // expected-warning {{variable 'a21' is uninitialized when used within its own initialization}} + + // FIXME: Make the local uninitialized warning consistant with the global + // uninitialized checking. + A *a22 = new A(a22->count); // expected-warning {{variable 'a22' is uninitialized when used within its own initialization}} + A *a23 = new A(a23->ONE); // expected-warning {{variable 'a23' is uninitialized when used within its own initialization}} + A *a24 = new A(a24->TWO); // expected-warning {{variable 'a24' is uninitialized when used within its own initialization}} + A *a25 = new A(a25->zero()); // expected-warning {{variable 'a25' is uninitialized when used within its own initialization}} + + A *a26 = new A(a26->get()); // expected-warning {{variable 'a26' is uninitialized when used within its own initialization}} + A *a27 = new A(a27->get2()); // expected-warning {{variable 'a27' is uninitialized when used within its own initialization}} + A *a28 = new A(a28->num); // expected-warning {{variable 'a28' is uninitialized when used within its own initialization}} } bool x; @@ -138,6 +151,17 @@ A a16(&a16.num); // expected-warning {{variable 'a16' is uninitialized when use 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}} +A a20{a20}; // expected-warning {{variable 'a20' is uninitialized when used within its own initialization}} +A a21 = {a21}; // expected-warning {{variable 'a21' is uninitialized when used within its own initialization}} + +A *a22 = new A(a22->count); +A *a23 = new A(a23->ONE); +A *a24 = new A(a24->TWO); +A *a25 = new A(a25->zero()); + +A *a26 = new A(a26->get()); // expected-warning {{variable 'a26' is uninitialized when used within its own initialization}} +A *a27 = new A(a27->get2()); // expected-warning {{variable 'a27' is uninitialized when used within its own initialization}} +A *a28 = new A(a28->num); // expected-warning {{variable 'a28' is uninitialized when used within its own initialization}} struct B { // POD struct. @@ -150,6 +174,11 @@ B getB(int x) { return B(); }; B getB(int *x) { return B(); }; B getB(B *b) { return B(); }; +B* getPtrB() { return 0; }; +B* getPtrB(int x) { return 0; }; +B* getPtrB(int *x) { return 0; }; +B* getPtrB(B **b) { return 0; }; + void setupB() { B b1; B b2(b1); @@ -166,18 +195,56 @@ void setupB() { B b8 = getB(b8.x); // expected-warning {{variable 'b8' is uninitialized when used within its own initialization}} B b9 = getB(b9.y); // expected-warning {{variable 'b9' is uninitialized when used within its own initialization}} B b10 = getB(-b10.x); // expected-warning {{variable 'b10' is uninitialized when used within its own initialization}} + + B* b11 = 0; + B* b12(b11); + B* b13 = getPtrB(); + B* b14 = getPtrB(&b14); + + (void) b12; + (void) b13; + + B* b15 = getPtrB(b15->x); // expected-warning {{variable 'b15' is uninitialized when used within its own initialization}} + B* b16 = getPtrB(b16->y); // expected-warning {{variable 'b16' is uninitialized when used within its own initialization}} + + B b17 = { b17.x = 5, b17.y = 0 }; + B b18 = { b18.x + 1, b18.y }; // expected-warning 2{{variable 'b18' is uninitialized when used within its own initialization}} } +B b1; +B b2(b1); +B b3 = { 5, &b3.x }; +B b4 = getB(); +B b5 = getB(&b5); +B b6 = getB(&b6.x); + +B b7(b7); // expected-warning {{variable 'b7' is uninitialized when used within its own initialization}} +B b8 = getB(b8.x); // expected-warning {{variable 'b8' is uninitialized when used within its own initialization}} +B b9 = getB(b9.y); // expected-warning {{variable 'b9' is uninitialized when used within its own initialization}} +B b10 = getB(-b10.x); // expected-warning {{variable 'b10' is uninitialized when used within its own initialization}} + +B* b11 = 0; +B* b12(b11); +B* b13 = getPtrB(); +B* b14 = getPtrB(&b14); + +B* b15 = getPtrB(b15->x); // expected-warning {{variable 'b15' is uninitialized when used within its own initialization}} +B* b16 = getPtrB(b16->y); // expected-warning {{variable 'b16' is uninitialized when used within its own initialization}} + +B b17 = { b17.x = 5, b17.y = 0 }; +B b18 = { b18.x + 1, b18.y }; // expected-warning 2{{variable 'b18' is uninitialized when used within its own initialization}} + + // Also test similar constructs in a field's initializer. struct S { int x; void *ptr; - S(bool (*)[1]) : x(x) {} // expected-warning {{field is uninitialized when used here}} - S(bool (*)[2]) : x(x + 1) {} // expected-warning {{field is uninitialized when used here}} - S(bool (*)[3]) : x(x + x) {} // expected-warning 2{{field is uninitialized when used here}} - S(bool (*)[4]) : x(static_cast<long>(x) + 1) {} // expected-warning {{field is uninitialized when used here}} - S(bool (*)[5]) : x(foo(x)) {} // expected-warning {{field is uninitialized when used here}} + S(bool (*)[1]) : x(x) {} // expected-warning {{field 'x' is uninitialized when used here}} + S(bool (*)[2]) : x(x + 1) {} // expected-warning {{field 'x' is uninitialized when used here}} + S(bool (*)[3]) : x(x + x) {} // expected-warning 2{{field 'x' is uninitialized when used here}} + S(bool (*)[4]) : x(static_cast<long>(x) + 1) {} // expected-warning {{field 'x' is uninitialized when used here}} + S(bool (*)[5]) : x(foo(x)) {} // expected-warning {{field 'x' is uninitialized when used here}} // These don't actually require the value of x and so shouldn't warn. S(char (*)[1]) : x(sizeof(x)) {} // rdar://8610363 @@ -262,8 +329,8 @@ namespace { C c; D(char (*)[1]) : c(c.b.a.A1) {} D(char (*)[2]) : c(c.b.a.A2()) {} - D(char (*)[3]) : c(c.b.a.A3) {} // expected-warning {{field is uninitialized when used here}} - D(char (*)[4]) : c(c.b.a.A4()) {} // expected-warning {{field is uninitialized when used here}} + D(char (*)[3]) : c(c.b.a.A3) {} // expected-warning {{field 'c' is uninitialized when used here}} + D(char (*)[4]) : c(c.b.a.A4()) {} // expected-warning {{field 'c' is uninitialized when used here}} // c::a is static, so it is already initialized D(char (*)[5]) : c(c.a.A1) {} @@ -274,21 +341,21 @@ namespace { struct E { int a, b, c; - E(char (*)[1]) : a(a ? b : c) {} // expected-warning {{field is uninitialized when used here}} - E(char (*)[2]) : a(b ? a : a) {} // expected-warning 2{{field is uninitialized when used here}} - E(char (*)[3]) : a(b ? (a) : c) {} // expected-warning {{field is uninitialized when used here}} - E(char (*)[4]) : a(b ? c : (a+c)) {} // expected-warning {{field is uninitialized when used here}} + E(char (*)[1]) : a(a ? b : c) {} // expected-warning {{field 'a' is uninitialized when used here}} + E(char (*)[2]) : a(b ? a : a) {} // expected-warning 2{{field 'a' is uninitialized when used here}} + E(char (*)[3]) : a(b ? (a) : c) {} // expected-warning {{field 'a' is uninitialized when used here}} + E(char (*)[4]) : a(b ? c : (a+c)) {} // expected-warning {{field 'a' is uninitialized when used here}} E(char (*)[5]) : a(b ? c : b) {} - E(char (*)[6]) : a(a ?: a) {} // expected-warning 2{{field is uninitialized when used here}} - E(char (*)[7]) : a(b ?: a) {} // expected-warning {{field is uninitialized when used here}} - E(char (*)[8]) : a(a ?: c) {} // expected-warning {{field is uninitialized when used here}} + E(char (*)[6]) : a(a ?: a) {} // expected-warning 2{{field 'a' is uninitialized when used here}} + E(char (*)[7]) : a(b ?: a) {} // expected-warning {{field 'a' is uninitialized when used here}} + E(char (*)[8]) : a(a ?: c) {} // expected-warning {{field 'a' is uninitialized when used here}} E(char (*)[9]) : a(b ?: c) {} E(char (*)[10]) : a((a, a, b)) {} - E(char (*)[11]) : a((c + a, a + 1, b)) {} // expected-warning 2{{field is uninitialized when used here}} - E(char (*)[12]) : a((b + c, c, a)) {} // expected-warning {{field is uninitialized when used here}} - E(char (*)[13]) : a((a, a, a, a)) {} // expected-warning {{field is uninitialized when used here}} + E(char (*)[11]) : a((c + a, a + 1, b)) {} // expected-warning 2{{field 'a' is uninitialized when used here}} + E(char (*)[12]) : a((b + c, c, a)) {} // expected-warning {{field 'a' is uninitialized when used here}} + E(char (*)[13]) : a((a, a, a, a)) {} // expected-warning {{field 'a' is uninitialized when used here}} E(char (*)[14]) : a((b, c, c)) {} }; @@ -304,16 +371,16 @@ namespace { struct G { F f1, f2; F *f3, *f4; - G(char (*)[1]) : f1(f1) {} // expected-warning {{field is uninitialized when used here}} + G(char (*)[1]) : f1(f1) {} // expected-warning {{field 'f1' is uninitialized when used here}} G(char (*)[2]) : f2(f1) {} G(char (*)[3]) : f2(F()) {} - G(char (*)[4]) : f1(f1.*ptr) {} // expected-warning {{field is uninitialized when used here}} + G(char (*)[4]) : f1(f1.*ptr) {} // expected-warning {{field 'f1' is uninitialized when used here}} G(char (*)[5]) : f2(f1.*ptr) {} - G(char (*)[6]) : f3(f3) {} // expected-warning {{field is uninitialized when used here}} - G(char (*)[7]) : f3(f3->*f_ptr) {} // expected-warning {{field is uninitialized when used here}} - G(char (*)[8]) : f3(new F(f3->*ptr)) {} // expected-warning {{field is uninitialized when used here}} + G(char (*)[6]) : f3(f3) {} // expected-warning {{field 'f3' is uninitialized when used here}} + G(char (*)[7]) : f3(f3->*f_ptr) {} // expected-warning {{field 'f3' is uninitialized when used here}} + G(char (*)[8]) : f3(new F(f3->*ptr)) {} // expected-warning {{field 'f3' is uninitialized when used here}} }; } @@ -379,21 +446,53 @@ namespace statics { } } +namespace in_class_initializers { + struct S { + S() : a(a + 1) {} // expected-warning{{field 'a' is uninitialized when used here}} + int a = 42; // Note: because a is in a member initializer list, this initialization is ignored. + }; + + struct T { + T() : b(a + 1) {} // No-warning. + int a = 42; + int b; + }; + + struct U { + U() : a(b + 1), b(a + 1) {} // FIXME: Warn here. + int a = 42; // Note: because a and b are in the member initializer list, these initializers are ignored. + int b = 1; + }; +} + namespace references { - int &a = a; // expected-warning{{variable 'a' is uninitialized when used within its own initialization}} + int &a = a; // expected-warning{{reference 'a' is not yet bound to a value when used within its own initialization}} + int &b(b); // expected-warning{{reference 'b' is not yet bound to a value when used within its own initialization}} + int &c = a ? b : c; // expected-warning{{reference 'c' is not yet bound to a value when used within its own initialization}} + int &d{d}; // expected-warning{{reference 'd' is not yet bound to a value when used within its own initialization}} struct S { - S() : a(a) {} // expected-warning{{field is uninitialized when used here}} + S() : a(a) {} // expected-warning{{reference 'a' is not yet bound to a value when used here}} int &a; }; void f() { - int &a = a; // expected-warning{{variable 'a' is uninitialized when used within its own initialization}} + int &a = a; // expected-warning{{reference 'a' is not yet bound to a value when used within its own initialization}} + int &b(b); // expected-warning{{reference 'b' is not yet bound to a value when used within its own initialization}} + int &c = a ? b : c; // expected-warning{{reference 'c' is not yet bound to a value when used within its own initialization}} + int &d{d}; // expected-warning{{reference 'd' is not yet bound to a value when used within its own initialization}} } struct T { T() : a(b), b(a) {} // FIXME: Warn here. int &a, &b; - int &c = c; // FIXME: Warn here. + int &c = c; // expected-warning{{reference 'c' is not yet bound to a value when used here}} + }; + + int x; + struct U { + U() : b(a) {} // No-warning. + int &a = x; + int &b; }; } |