diff options
author | Hans Wennborg <hans@hanshq.net> | 2012-08-17 10:12:33 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2012-08-17 10:12:33 +0000 |
commit | e1fdb059c6df2ac8526f987cd054219975714e0c (patch) | |
tree | 6628e445cf4ccd58c3457b0556d9c06d95286582 /clang/test/SemaCXX/uninitialized.cpp | |
parent | 5f487de8a3eccfa15874ef101bb66c0a07c86853 (diff) | |
download | bcm5719-llvm-e1fdb059c6df2ac8526f987cd054219975714e0c.tar.gz bcm5719-llvm-e1fdb059c6df2ac8526f987cd054219975714e0c.zip |
Warn about self-initialization of references.
Initializing a reference with itself, e.g. "int &a = a;" seems like a
very bad idea.
llvm-svn: 162093
Diffstat (limited to 'clang/test/SemaCXX/uninitialized.cpp')
-rw-r--r-- | clang/test/SemaCXX/uninitialized.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/uninitialized.cpp b/clang/test/SemaCXX/uninitialized.cpp index 890f2129303..385548b51cc 100644 --- a/clang/test/SemaCXX/uninitialized.cpp +++ b/clang/test/SemaCXX/uninitialized.cpp @@ -378,3 +378,22 @@ namespace statics { } } } + +namespace references { + int &a = a; // expected-warning{{variable 'a' is uninitialized when used within its own initialization}} + + struct S { + S() : a(a) {} // expected-warning{{field is uninitialized when used here}} + int &a; + }; + + void f() { + int &a = a; // expected-warning{{variable 'a' is uninitialized 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. + }; +} |