diff options
author | Hans Wennborg <hans@hanshq.net> | 2012-09-18 15:58:06 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2012-09-18 15:58:06 +0000 |
commit | 44fd70a3ad43b8e7b27af79f8011c7f5b90c841f (patch) | |
tree | 3167e7fabeb747e20a4f5210bb092983d8acfad2 /clang/test/SemaCXX/uninitialized.cpp | |
parent | eb2c8f0fc69d09f0318cdcef7398f867402eaecd (diff) | |
download | bcm5719-llvm-44fd70a3ad43b8e7b27af79f8011c7f5b90c841f.tar.gz bcm5719-llvm-44fd70a3ad43b8e7b27af79f8011c7f5b90c841f.zip |
Warn about self references in in-class initializers.
This makes Clang warn about self references in in-class initializers,
for example:
struct S {
int a = a + 42;
};
This basically just moves UninitializedFieldVisitor up a bit in
SemaDeclCXX.cpp, and adds a call to it from ActOnCXXInClassMemberInitializer.
llvm-svn: 164131
Diffstat (limited to 'clang/test/SemaCXX/uninitialized.cpp')
-rw-r--r-- | clang/test/SemaCXX/uninitialized.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/clang/test/SemaCXX/uninitialized.cpp b/clang/test/SemaCXX/uninitialized.cpp index 0633764c1b4..baee272ed58 100644 --- a/clang/test/SemaCXX/uninitialized.cpp +++ b/clang/test/SemaCXX/uninitialized.cpp @@ -379,6 +379,25 @@ namespace statics { } } +namespace in_class_initializers { + struct S { + S() : a(a + 1) {} // expected-warning{{field 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{{reference 'a' is not yet bound to a value when used within its own initialization}} @@ -394,6 +413,13 @@ namespace references { 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 is not yet bound to a value when used here}} + }; + + int x; + struct U { + U() : b(a) {} // No-warning. + int &a = x; + int &b; }; } |