From ad5bbcceb704e9ce5e94a010492a12b7400f3703 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 1 Aug 2018 01:03:33 +0000 Subject: [PATCH] Avoid exposing name for range-based for '__range' variables in lifetime warnings. llvm-svn: 338467 --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 12 +++++++----- clang/lib/Sema/SemaInit.cpp | 8 +++++--- clang/test/SemaCXX/attr-lifetimebound.cpp | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 8eef30e710cb..586f65e9201c 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -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; def warn_new_dangling_reference : Warning< "temporary bound to reference member of allocated object " diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 5fa8a3c6c448..f006a677b678 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -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(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; } diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp b/clang/test/SemaCXX/attr-lifetimebound.cpp index b376819ad578..90124c323d02 100644 --- a/clang/test/SemaCXX/attr-lifetimebound.cpp +++ b/clang/test/SemaCXX/attr-lifetimebound.cpp @@ -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