]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: location of lambda object and conversion call
authorJason Merrill <jason@redhat.com>
Mon, 15 Nov 2021 04:18:19 +0000 (23:18 -0500)
committerJason Merrill <jason@redhat.com>
Mon, 15 Nov 2021 07:52:36 +0000 (02:52 -0500)
Two things that had poor location info: we weren't giving the TARGET_EXPR
for a lambda object any location, and the call to a conversion function was
getting whatever input_location happened to be.

gcc/cp/ChangeLog:

* call.c (perform_implicit_conversion_flags): Use the location of
the argument.
* lambda.c (build_lambda_object): Set location on the TARGET_EXPR.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/lambda/lambda-switch.C: Adjust expected location.

gcc/cp/call.c
gcc/cp/lambda.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-switch.C

index 01ac114a62c83c2252b82bbe1d6f774d3f47d0e2..4ee21c7bdbdfaf2ff225576109a44a44ec7dee97 100644 (file)
@@ -12549,7 +12549,11 @@ perform_implicit_conversion_flags (tree type, tree expr,
        IMPLICIT_CONV_EXPR_BRACED_INIT (expr) = true;
     }
   else
-    expr = convert_like (conv, expr, complain);
+    {
+      /* Give a conversion call the same location as expr.  */
+      iloc_sentinel il (loc);
+      expr = convert_like (conv, expr, complain);
+    }
 
   /* Free all the conversions we allocated.  */
   obstack_free (&conversion_obstack, p);
index 2e9d38bbe832702804ddcaffc4024ce930a74843..f68c68ca16e64072e9880e849ac72f1424bf7328 100644 (file)
@@ -57,14 +57,13 @@ build_lambda_object (tree lambda_expr)
      - cp_parser_functional_cast  */
   vec<constructor_elt, va_gc> *elts = NULL;
   tree node, expr, type;
-  location_t saved_loc;
 
   if (processing_template_decl || lambda_expr == error_mark_node)
     return lambda_expr;
 
   /* Make sure any error messages refer to the lambda-introducer.  */
-  saved_loc = input_location;
-  input_location = LAMBDA_EXPR_LOCATION (lambda_expr);
+  location_t loc = LAMBDA_EXPR_LOCATION (lambda_expr);
+  iloc_sentinel il (loc);
 
   for (node = LAMBDA_EXPR_CAPTURE_LIST (lambda_expr);
        node;
@@ -117,10 +116,10 @@ build_lambda_object (tree lambda_expr)
   type = LAMBDA_EXPR_CLOSURE (lambda_expr);
   CLASSTYPE_NON_AGGREGATE (type) = 0;
   expr = finish_compound_literal (type, expr, tf_warning_or_error);
+  protected_set_expr_location (expr, loc);
   CLASSTYPE_NON_AGGREGATE (type) = 1;
 
  out:
-  input_location = saved_loc;
   return expr;
 }
 
index d05c9760709a9fe23da38beb825d6e79384c0e9d..e417967a17e486e554193ce358836bd46884917e 100644 (file)
@@ -16,11 +16,11 @@ main ()
              break;            // { dg-error "break" }
            }
          };
-         l = []()
+         l = []()              // { dg-warning "statement will never be executed" }
            {
            case 3:             // { dg-error "case" }
              break;            // { dg-error "break" }
-           };          // { dg-warning "statement will never be executed" }
+           };
        }
     }
 }