[cfe-commits] r162198 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp test/Analysis/stack-addr-ps.cpp test/SemaCXX/references.cpp test/SemaCXX/uninitialized.cpp
Hans Wennborg
hans at hanshq.net
Mon Aug 20 01:52:23 PDT 2012
Author: hans
Date: Mon Aug 20 03:52:22 2012
New Revision: 162198
URL: http://llvm.org/viewvc/llvm-project?rev=162198&view=rev
Log:
Better wording for reference self-initialization warning.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/Analysis/stack-addr-ps.cpp
cfe/trunk/test/SemaCXX/references.cpp
cfe/trunk/test/SemaCXX/uninitialized.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=162198&r1=162197&r2=162198&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Aug 20 03:52:22 2012
@@ -1216,9 +1216,16 @@
"uninitialized reference member is here">;
def warn_field_is_uninit : Warning<"field is uninitialized when used here">,
InGroup<Uninitialized>;
+def warn_reference_field_is_uninit : Warning<
+ "reference is not yet bound to a value when used here">,
+ InGroup<Uninitialized>;
def warn_uninit_self_reference_in_init : Warning<
"variable %0 is uninitialized when used within its own initialization">,
InGroup<Uninitialized>;
+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<Uninitialized>;
def warn_uninit_var : Warning<
"variable %0 is uninitialized when %select{used here|captured by block}1">,
InGroup<Uninitialized>, DefaultIgnore;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=162198&r1=162197&r2=162198&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Aug 20 03:52:22 2012
@@ -6275,8 +6275,11 @@
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());
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=162198&r1=162197&r2=162198&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Aug 20 03:52:22 2012
@@ -2080,7 +2080,10 @@
}
if (VD == ME->getMemberDecl() && isa<CXXThisExpr>(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;
}
}
Modified: cfe/trunk/test/Analysis/stack-addr-ps.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/stack-addr-ps.cpp?rev=162198&r1=162197&r2=162198&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/stack-addr-ps.cpp (original)
+++ cfe/trunk/test/Analysis/stack-addr-ps.cpp Mon Aug 20 03:52:22 2012
@@ -87,6 +87,6 @@
// 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}}
}
Modified: cfe/trunk/test/SemaCXX/references.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/references.cpp?rev=162198&r1=162197&r2=162198&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/references.cpp (original)
+++ cfe/trunk/test/SemaCXX/references.cpp Mon Aug 20 03:52:22 2012
@@ -136,4 +136,4 @@
}
// 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}}
Modified: cfe/trunk/test/SemaCXX/uninitialized.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninitialized.cpp?rev=162198&r1=162197&r2=162198&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/uninitialized.cpp (original)
+++ cfe/trunk/test/SemaCXX/uninitialized.cpp Mon Aug 20 03:52:22 2012
@@ -380,15 +380,15 @@
}
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 {
More information about the cfe-commits
mailing list