<div dir="ltr">There's definitely scope for improving this diagnostic text further. Right now I don't think there's an easy way to figure out that the variable is the range variable in a range-based for loop, but I think that case is common enough that that's the level of special-case we should be looking at here. If we track that state, something like "error: range refers to a temporary object that will be destroyed before the first iteration of the loop" would seem much preferable.<br><br><div class="gmail_quote"><div dir="ltr">On Tue, 7 Aug 2018 at 09:28, David Blaikie via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Reckon there's a chance of improved diagnostic text in cases like this? Will users understand what the problem is/how to fix it when they read "<span style="color:rgb(33,33,33)">temporary implicitly bound to local reference will be destroyed at the end of the full-expression" - feels very standard-ese-y to me? & I appreciate teh desire/need for precision, I wonder if there's better ways to communicate it to the user... :/<br></span></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Jul 31, 2018 at 6:03 PM Richard Smith via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rsmith<br>
Date: Tue Jul 31 18:03:33 2018<br>
New Revision: 338467<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=338467&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=338467&view=rev</a><br>
Log:<br>
Avoid exposing name for range-based for '__range' variables in lifetime warnings.<br>
<br>
Modified:<br>
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
    cfe/trunk/lib/Sema/SemaInit.cpp<br>
    cfe/trunk/test/SemaCXX/attr-lifetimebound.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=338467&r1=338466&r2=338467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=338467&r1=338466&r2=338467&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jul 31 18:03:33 2018<br>
@@ -7875,7 +7875,8 @@ def warn_ret_addr_label : Warning<<br>
 def err_ret_local_block : Error<<br>
   "returning block that lives on the local stack">;<br>
 def note_local_var_initializer : Note<<br>
-  "%select{via initialization of|binding reference}0 variable %1 here">;<br>
+  "%select{via initialization of|binding reference}0 variable "<br>
+  "%select{%2 |}1here">;<br>
 def note_init_with_default_member_initalizer : Note<<br>
   "initializing field %0 with default member initializer">;<br>
<br>
@@ -7907,13 +7908,14 @@ def note_lifetime_extending_member_decla<br>
   "member with %select{reference|'std::initializer_list'}0 subobject}1 "<br>
   "declared here">;<br>
 def warn_dangling_variable : Warning<<br>
-  "%select{temporary %select{whose address is used as value of|bound to}3 "<br>
-  "%select{%select{|reference }3member of local variable|"<br>
-  "local %select{variable|reference}3}1|"<br>
+  "%select{temporary %select{whose address is used as value of|"<br>
+  "%select{|implicitly }2bound to}4 "<br>
+  "%select{%select{|reference }4member of local variable|"<br>
+  "local %select{variable|reference}4}1|"<br>
   "array backing "<br>
   "%select{initializer list subobject of local variable|"<br>
   "local initializer list}1}0 "<br>
-  "%2 will be destroyed at the end of the full-expression">,<br>
+  "%select{%3 |}2will be destroyed at the end of the full-expression">,<br>
   InGroup<Dangling>;<br>
 def warn_new_dangling_reference : Warning<<br>
   "temporary bound to reference member of allocated object "<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaInit.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=338467&r1=338466&r2=338467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=338467&r1=338466&r2=338467&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaInit.cpp Tue Jul 31 18:03:33 2018<br>
@@ -6847,8 +6847,9 @@ void Sema::checkInitializerLifetime(cons<br>
           return false;<br>
<br>
         Diag(DiagLoc, diag::warn_dangling_variable)<br>
-            << RK << !Entity.getParent() << ExtendingEntity->getDecl()<br>
-            << Init->isGLValue() << DiagRange;<br>
+            << RK << !Entity.getParent()<br>
+            << ExtendingEntity->getDecl()->isImplicit()<br>
+            << ExtendingEntity->getDecl() << Init->isGLValue() << DiagRange;<br>
       }<br>
       break;<br>
     }<br>
@@ -6969,7 +6970,8 @@ void Sema::checkInitializerLifetime(cons<br>
       case IndirectLocalPathEntry::VarInit:<br>
         const VarDecl *VD = cast<VarDecl>(Elem.D);<br>
         Diag(VD->getLocation(), diag::note_local_var_initializer)<br>
-            << VD->getType()->isReferenceType() << VD->getDeclName()<br>
+            << VD->getType()->isReferenceType()<br>
+            << VD->isImplicit() << VD->getDeclName()<br>
             << nextPathEntryRange(Path, I + 1, L);<br>
         break;<br>
       }<br>
<br>
Modified: cfe/trunk/test/SemaCXX/attr-lifetimebound.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-lifetimebound.cpp?rev=338467&r1=338466&r2=338467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-lifetimebound.cpp?rev=338467&r1=338466&r2=338467&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/attr-lifetimebound.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/attr-lifetimebound.cpp Tue Jul 31 18:03:33 2018<br>
@@ -101,7 +101,7 @@ namespace p0936r0_examples {<br>
   std::vector make_vector();<br>
   void use_reversed_range() {<br>
     // FIXME: Don't expose the name of the internal range variable.<br>
-    for (auto x : reversed(make_vector())) {} // expected-warning {{temporary bound to local reference '__range1'}}<br>
+    for (auto x : reversed(make_vector())) {} // expected-warning {{temporary implicitly bound to local reference will be destroyed at the end of the full-expression}}<br>
   }<br>
<br>
   template <typename K, typename V><br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div>