summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2012-08-17 10:12:33 +0000
committerHans Wennborg <hans@hanshq.net>2012-08-17 10:12:33 +0000
commite1fdb059c6df2ac8526f987cd054219975714e0c (patch)
tree6628e445cf4ccd58c3457b0556d9c06d95286582 /clang/test
parent5f487de8a3eccfa15874ef101bb66c0a07c86853 (diff)
downloadbcm5719-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')
-rw-r--r--clang/test/Analysis/stack-addr-ps.cpp2
-rw-r--r--clang/test/SemaCXX/convert-to-bool.cpp3
-rw-r--r--clang/test/SemaCXX/references.cpp2
-rw-r--r--clang/test/SemaCXX/uninitialized.cpp19
4 files changed, 22 insertions, 4 deletions
diff --git a/clang/test/Analysis/stack-addr-ps.cpp b/clang/test/Analysis/stack-addr-ps.cpp
index b21a03dc38a..cbdb143c185 100644
--- a/clang/test/Analysis/stack-addr-ps.cpp
+++ b/clang/test/Analysis/stack-addr-ps.cpp
@@ -87,6 +87,6 @@ struct TS {
// rdar://11345441
int* f5() {
- int& i = i; // expected-warning {{Assigned value is garbage or undefined}} expected-note {{binding reference variable 'i' here}}
+ int& i = i; // expected-warning {{Assigned value is garbage or undefined}} expected-note {{binding reference variable 'i' here}} expected-warning{{variable 'i' is uninitialized when used within its own initialization}}
return &i; // expected-warning {{address of stack memory associated with local variable 'i' returned}}
}
diff --git a/clang/test/SemaCXX/convert-to-bool.cpp b/clang/test/SemaCXX/convert-to-bool.cpp
index c9a355549fd..b52f11c93d3 100644
--- a/clang/test/SemaCXX/convert-to-bool.cpp
+++ b/clang/test/SemaCXX/convert-to-bool.cpp
@@ -62,6 +62,5 @@ struct C {
void test_copy_init_conversions(C c) {
A &a = c; // expected-error{{no viable conversion from 'C' to 'A'}}
- B &b = b; // okay
+ B &b = c; // okay
}
-
diff --git a/clang/test/SemaCXX/references.cpp b/clang/test/SemaCXX/references.cpp
index 70d3799a0ea..028c6909210 100644
--- a/clang/test/SemaCXX/references.cpp
+++ b/clang/test/SemaCXX/references.cpp
@@ -136,4 +136,4 @@ namespace PR8608 {
}
// The following crashed trying to recursively evaluate the LValue.
-const int &do_not_crash = do_not_crash;
+const int &do_not_crash = do_not_crash; // expected-warning{{variable 'do_not_crash' is uninitialized when used within its own initialization}}
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.
+ };
+}
OpenPOWER on IntegriCloud