Avoid exposing name for range-based for '__range' variables in lifetime warnings.

llvm-svn: 338467
This commit is contained in:
Richard Smith 2018-08-01 01:03:33 +00:00
parent 37b3c1775b
commit ad5bbcceb7
3 changed files with 13 additions and 9 deletions

View File

@ -7875,7 +7875,8 @@ def warn_ret_addr_label : Warning<
def err_ret_local_block : Error<
"returning block that lives on the local stack">;
def note_local_var_initializer : Note<
"%select{via initialization of|binding reference}0 variable %1 here">;
"%select{via initialization of|binding reference}0 variable "
"%select{%2 |}1here">;
def note_init_with_default_member_initalizer : Note<
"initializing field %0 with default member initializer">;
@ -7907,13 +7908,14 @@ def note_lifetime_extending_member_declared_here : Note<
"member with %select{reference|'std::initializer_list'}0 subobject}1 "
"declared here">;
def warn_dangling_variable : Warning<
"%select{temporary %select{whose address is used as value of|bound to}3 "
"%select{%select{|reference }3member of local variable|"
"local %select{variable|reference}3}1|"
"%select{temporary %select{whose address is used as value of|"
"%select{|implicitly }2bound to}4 "
"%select{%select{|reference }4member of local variable|"
"local %select{variable|reference}4}1|"
"array backing "
"%select{initializer list subobject of local variable|"
"local initializer list}1}0 "
"%2 will be destroyed at the end of the full-expression">,
"%select{%3 |}2will be destroyed at the end of the full-expression">,
InGroup<Dangling>;
def warn_new_dangling_reference : Warning<
"temporary bound to reference member of allocated object "

View File

@ -6847,8 +6847,9 @@ void Sema::checkInitializerLifetime(const InitializedEntity &Entity,
return false;
Diag(DiagLoc, diag::warn_dangling_variable)
<< RK << !Entity.getParent() << ExtendingEntity->getDecl()
<< Init->isGLValue() << DiagRange;
<< RK << !Entity.getParent()
<< ExtendingEntity->getDecl()->isImplicit()
<< ExtendingEntity->getDecl() << Init->isGLValue() << DiagRange;
}
break;
}
@ -6969,7 +6970,8 @@ void Sema::checkInitializerLifetime(const InitializedEntity &Entity,
case IndirectLocalPathEntry::VarInit:
const VarDecl *VD = cast<VarDecl>(Elem.D);
Diag(VD->getLocation(), diag::note_local_var_initializer)
<< VD->getType()->isReferenceType() << VD->getDeclName()
<< VD->getType()->isReferenceType()
<< VD->isImplicit() << VD->getDeclName()
<< nextPathEntryRange(Path, I + 1, L);
break;
}

View File

@ -101,7 +101,7 @@ namespace p0936r0_examples {
std::vector make_vector();
void use_reversed_range() {
// FIXME: Don't expose the name of the internal range variable.
for (auto x : reversed(make_vector())) {} // expected-warning {{temporary bound to local reference '__range1'}}
for (auto x : reversed(make_vector())) {} // expected-warning {{temporary implicitly bound to local reference will be destroyed at the end of the full-expression}}
}
template <typename K, typename V>