diff options
author | Richard Trieu <rtrieu@google.com> | 2012-08-14 23:50:52 +0000 |
---|---|---|
committer | Richard Trieu <rtrieu@google.com> | 2012-08-14 23:50:52 +0000 |
commit | 1b4b1461da093bfcb85edfb67710d21f79c7f16c (patch) | |
tree | d8b30aa8139e323f1ab9f4204a70a20474c70763 /test/SemaCXX/uninitialized.cpp | |
parent | 27ef16b326b9a9dd2440e5d1cc884e27f07e13a3 (diff) |
Check local static variables for self reference on initialization.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161909 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/uninitialized.cpp')
-rw-r--r-- | test/SemaCXX/uninitialized.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/test/SemaCXX/uninitialized.cpp b/test/SemaCXX/uninitialized.cpp index 13d287bf1a..890f212930 100644 --- a/test/SemaCXX/uninitialized.cpp +++ b/test/SemaCXX/uninitialized.cpp @@ -316,3 +316,65 @@ namespace { G(char (*)[8]) : f3(new F(f3->*ptr)) {} // expected-warning {{field is uninitialized when used here}} }; } + +namespace statics { + static int a = a; // no-warning: used to signal intended lack of initialization. + static int b = b + 1; // expected-warning {{variable 'b' is uninitialized when used within its own initialization}} + static int c = (c + c); // expected-warning 2{{variable 'c' is uninitialized when used within its own initialization}} + static int e = static_cast<long>(e) + 1; // expected-warning {{variable 'e' is uninitialized when used within its own initialization}} + static int f = foo(f); // expected-warning {{variable 'f' is uninitialized when used within its own initialization}} + + // Thes don't warn as they don't require the value. + static int g = sizeof(g); + int gg = g; // Silence unneeded warning + static void* ptr = &ptr; + static int h = bar(&h); + static int i = boo(i); + static int j = far(j); + static int k = __alignof__(k); + + static int l = k ? l : l; // expected-warning 2{{variable 'l' is uninitialized when used within its own initialization}} + static int m = 1 + (k ? m : m); // expected-warning 2{{variable 'm' is uninitialized when used within its own initialization}} + static int n = -n; // expected-warning {{variable 'n' is uninitialized when used within its own initialization}} + + void test() { + static int a = a; // no-warning: used to signal intended lack of initialization. + static int b = b + 1; // expected-warning {{variable 'b' is uninitialized when used within its own initialization}} + static int c = (c + c); // expected-warning 2{{variable 'c' is uninitialized when used within its own initialization}} + static int d = ({ d + d ;}); // expected-warning 2{{variable 'd' is uninitialized when used within its own initialization}} + static int e = static_cast<long>(e) + 1; // expected-warning {{variable 'e' is uninitialized when used within its own initialization}} + static int f = foo(f); // expected-warning {{variable 'f' is uninitialized when used within its own initialization}} + + // Thes don't warn as they don't require the value. + static int g = sizeof(g); + static void* ptr = &ptr; + static int h = bar(&h); + static int i = boo(i); + static int j = far(j); + static int k = __alignof__(k); + + static int l = k ? l : l; // expected-warning 2{{variable 'l' is uninitialized when used within its own initialization}} + static int m = 1 + (k ? m : m); // expected-warning 2{{variable 'm' is uninitialized when used within its own initialization}} + static int n = -n; // expected-warning {{variable 'n' is uninitialized when used within its own initialization}} + for (;;) { + static int a = a; // no-warning: used to signal intended lack of initialization. + static int b = b + 1; // expected-warning {{variable 'b' is uninitialized when used within its own initialization}} + static int c = (c + c); // expected-warning 2{{variable 'c' is uninitialized when used within its own initialization}} + static int d = ({ d + d ;}); // expected-warning 2{{variable 'd' is uninitialized when used within its own initialization}} + static int e = static_cast<long>(e) + 1; // expected-warning {{variable 'e' is uninitialized when used within its own initialization}} + static int f = foo(f); // expected-warning {{variable 'f' is uninitialized when used within its own initialization}} + + // Thes don't warn as they don't require the value. + static int g = sizeof(g); + static void* ptr = &ptr; + static int h = bar(&h); + static int i = boo(i); + static int j = far(j); + static int k = __alignof__(k); + + static int l = k ? l : l; // expected-warning 2{{variable 'l' is uninitialized when used within its own initialization}} + static int m = 1 + (k ? m : m); // expected-warning 2{{variable 'm' is uninitialized when used within its own initialization}} + static int n = -n; // expected-warning {{variable 'n' is uninitialized when used within its own initialization}} + } + } +} |