From 44fd70a3ad43b8e7b27af79f8011c7f5b90c841f Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Tue, 18 Sep 2012 15:58:06 +0000 Subject: 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 --- clang/test/SemaCXX/uninitialized.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'clang/test/SemaCXX/uninitialized.cpp') 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; }; } -- cgit v1.2.3