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

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 31 18:03:33 PDT 2018


Author: rsmith
Date: Tue Jul 31 18:03:33 2018
New Revision: 338467

URL: http://llvm.org/viewvc/llvm-project?rev=338467&view=rev
Log:
Avoid exposing name for range-based for '__range' variables in lifetime warnings.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/SemaCXX/attr-lifetimebound.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=338467&r1=338466&r2=338467&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jul 31 18:03:33 2018
@@ -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_decla
   "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 "

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=338467&r1=338466&r2=338467&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Tue Jul 31 18:03:33 2018
@@ -6847,8 +6847,9 @@ void Sema::checkInitializerLifetime(cons
           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(cons
       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;
       }

Modified: cfe/trunk/test/SemaCXX/attr-lifetimebound.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-lifetimebound.cpp?rev=338467&r1=338466&r2=338467&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-lifetimebound.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-lifetimebound.cpp Tue Jul 31 18:03:33 2018
@@ -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>




More information about the cfe-commits mailing list