summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/uninitialized.cpp
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2013-10-25 00:56:00 +0000
committerRichard Trieu <rtrieu@google.com>2013-10-25 00:56:00 +0000
commitef64e94d5c14281a3b354b08a69f3400d47896f0 (patch)
tree67e48d88f4b32bb0d315634e89f4a81c8f678695 /clang/test/SemaCXX/uninitialized.cpp
parent0145c5630698c51443900fb481fd53e1f926735e (diff)
downloadbcm5719-llvm-ef64e94d5c14281a3b354b08a69f3400d47896f0.tar.gz
bcm5719-llvm-ef64e94d5c14281a3b354b08a69f3400d47896f0.zip
Simplify and refactor the uninitialized field warning.
Change the uninitialized field warnings so that field initializers are checked inside the constructor. Previously, in class initializers were checked separately. Running one set of checks also simplifies the logic for preventing duplicate warnings. Added new checks to warn when an uninitialized field is used in base class initialization. Also fixed misspelling of uninitialized and moved all code for this warning together. llvm-svn: 193386
Diffstat (limited to 'clang/test/SemaCXX/uninitialized.cpp')
-rw-r--r--clang/test/SemaCXX/uninitialized.cpp66
1 files changed, 63 insertions, 3 deletions
diff --git a/clang/test/SemaCXX/uninitialized.cpp b/clang/test/SemaCXX/uninitialized.cpp
index 2fb0482cacb..4991ebee8b3 100644
--- a/clang/test/SemaCXX/uninitialized.cpp
+++ b/clang/test/SemaCXX/uninitialized.cpp
@@ -487,7 +487,8 @@ namespace references {
}
struct T {
- T() : a(b), b(a) {} // FIXME: Warn here.
+ T() // expected-note{{during field initialization in this constructor}}
+ : a(b), b(a) {} // expected-warning{{reference 'b' is not yet bound to a value when used here}}
int &a, &b;
int &c = c; // expected-warning{{reference 'c' is not yet bound to a value when used here}}
};
@@ -552,7 +553,9 @@ namespace record_fields {
B(char (*)[7]) : a(const_ref(a)) {}
B(char (*)[8]) : a(pointer(&a)) {}
B(char (*)[9]) : a(normal(a)) {} // expected-warning {{uninitialized}}
-
+ };
+ struct C {
+ C() {} // expected-note4{{in this constructor}}
A a1 = a1; // expected-warning {{uninitialized}}
A a2 = a2.get(); // expected-warning {{uninitialized}}
A a3 = a3.num();
@@ -563,6 +566,29 @@ namespace record_fields {
A a8 = pointer(&a8);
A a9 = normal(a9); // expected-warning {{uninitialized}}
};
+ struct D { // expected-note4{{in the implicit default constructor}}
+ A a1 = a1; // expected-warning {{uninitialized}}
+ A a2 = a2.get(); // expected-warning {{uninitialized}}
+ A a3 = a3.num();
+ A a4 = a4.copy(a4); // expected-warning {{uninitialized}}
+ A a5 = a5.something(a5);
+ A a6 = ref(a6);
+ A a7 = const_ref(a7);
+ A a8 = pointer(&a8);
+ A a9 = normal(a9); // expected-warning {{uninitialized}}
+ };
+ D d;
+ struct E {
+ A a1 = a1;
+ A a2 = a2.get();
+ A a3 = a3.num();
+ A a4 = a4.copy(a4);
+ A a5 = a5.something(a5);
+ A a6 = ref(a6);
+ A a7 = const_ref(a7);
+ A a8 = pointer(&a8);
+ A a9 = normal(a9);
+ };
}
namespace cross_field_warnings {
@@ -576,13 +602,14 @@ namespace cross_field_warnings {
struct B {
int a = b; // expected-warning{{field 'b' is uninitialized when used here}}
int b;
+ B() {} // expected-note{{during field initialization in this constructor}}
};
struct C {
int a;
int b = a; // expected-warning{{field 'a' is uninitialized when used here}}
C(char (*)[1]) : a(5) {}
- C(char (*)[2]) {}
+ C(char (*)[2]) {} // expected-note{{during field initialization in this constructor}}
};
struct D {
@@ -666,5 +693,38 @@ namespace cross_field_warnings {
P() : x(o.get()) { }
};
+ struct Q {
+ int a;
+ int b;
+ int &c;
+ Q() :
+ a(c = 5), // expected-warning{{reference 'c' is not yet bound to a value when used here}}
+ b(c), // expected-warning{{reference 'c' is not yet bound to a value when used here}}
+ c(a) {}
+ };
+
+ struct R {
+ int a;
+ int b;
+ int c;
+ int d = a + b + c;
+ R() : a(c = 5), b(c), c(a) {}
+ };
}
+namespace base_class {
+ struct A {
+ A (int) {}
+ };
+
+ struct B : public A {
+ int x;
+ B() : A(x) {} // expected-warning{{field 'x' is uninitialized when used here}}
+ };
+
+ struct C : public A {
+ int x;
+ int y;
+ C() : A(y = 4), x(y) {}
+ };
+}
OpenPOWER on IntegriCloud