From: Hans Wennborg Date: Mon, 20 Aug 2012 08:52:22 +0000 (+0000) Subject: Better wording for reference self-initialization warning. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5965b7c7ddf8d9635426943a05441c71cb59fef6;p=clang Better wording for reference self-initialization warning. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162198 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 0623966279..065b5b1bed 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1216,9 +1216,16 @@ def note_uninit_reference_member : Note< "uninitialized reference member is here">; def warn_field_is_uninit : Warning<"field is uninitialized when used here">, InGroup; +def warn_reference_field_is_uninit : Warning< + "reference is not yet bound to a value when used here">, + InGroup; def warn_uninit_self_reference_in_init : Warning< "variable %0 is uninitialized when used within its own initialization">, InGroup; +def warn_uninit_self_reference_in_reference_init : Warning< + "reference %0 is not yet bound to a value when used within its own" + " initialization">, + InGroup; def warn_uninit_var : Warning< "variable %0 is uninitialized when %select{used here|captured by block}1">, InGroup, DefaultIgnore; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 84ddf36ecc..cd6a60b47b 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -6275,8 +6275,11 @@ namespace { if (OrigDecl != ReferenceDecl) return; LookupResult Result(S, DRE->getNameInfo(), Sema::LookupOrdinaryName, Sema::NotForRedeclaration); + unsigned diag = isReferenceType + ? diag::warn_uninit_self_reference_in_reference_init + : diag::warn_uninit_self_reference_in_init; S.DiagRuntimeBehavior(DRE->getLocStart(), DRE, - S.PDiag(diag::warn_uninit_self_reference_in_init) + S.PDiag(diag) << Result.getLookupName() << OrigDecl->getLocation() << DRE->getSourceRange()); diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index eeac9b8e8d..2d3f2c0239 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -2080,7 +2080,10 @@ namespace { } if (VD == ME->getMemberDecl() && isa(Base)) { - S.Diag(ME->getExprLoc(), diag::warn_field_is_uninit); + unsigned diag = VD->getType()->isReferenceType() + ? diag::warn_reference_field_is_uninit + : diag::warn_field_is_uninit; + S.Diag(ME->getExprLoc(), diag); return; } } diff --git a/test/Analysis/stack-addr-ps.cpp b/test/Analysis/stack-addr-ps.cpp index cbdb143c18..a27bef793c 100644 --- a/test/Analysis/stack-addr-ps.cpp +++ b/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}} expected-warning{{variable 'i' is uninitialized when used within its own initialization}} + int& i = i; // expected-warning {{Assigned value is garbage or undefined}} expected-note {{binding reference variable 'i' here}} expected-warning{{reference 'i' is not yet bound to a value when used within its own initialization}} return &i; // expected-warning {{address of stack memory associated with local variable 'i' returned}} } diff --git a/test/SemaCXX/references.cpp b/test/SemaCXX/references.cpp index 028c690921..4f3dab0514 100644 --- a/test/SemaCXX/references.cpp +++ b/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; // expected-warning{{variable 'do_not_crash' is uninitialized when used within its own initialization}} +const int &do_not_crash = do_not_crash; // expected-warning{{reference 'do_not_crash' is not yet bound to a value when used within its own initialization}} diff --git a/test/SemaCXX/uninitialized.cpp b/test/SemaCXX/uninitialized.cpp index 385548b51c..0633764c1b 100644 --- a/test/SemaCXX/uninitialized.cpp +++ b/test/SemaCXX/uninitialized.cpp @@ -380,15 +380,15 @@ namespace statics { } namespace references { - int &a = a; // expected-warning{{variable 'a' is uninitialized when used within its own initialization}} + int &a = a; // expected-warning{{reference 'a' is not yet bound to a value when used within its own initialization}} struct S { - S() : a(a) {} // expected-warning{{field is uninitialized when used here}} + S() : a(a) {} // expected-warning{{reference is not yet bound to a value when used here}} int &a; }; void f() { - int &a = a; // expected-warning{{variable 'a' is uninitialized when used within its own initialization}} + int &a = a; // expected-warning{{reference 'a' is not yet bound to a value when used within its own initialization}} } struct T {