diff mbox series

[pushed] c++: conversion location

Message ID 20240915154856.463159-1-jason@redhat.com
State New
Headers show
Series [pushed] c++: conversion location | expand

Commit Message

Jason Merrill Sept. 15, 2024, 3:48 p.m. UTC
Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

It seems more useful for a conversion to have the location of the source
expression rather than the enclosing expression, such as a call that might
convert multiple arguments in different ways.

As a result, in srcloc17.C the recorded location of 'e' when
copy-initialized became that of the initializer rather than the variable,
since the semantic was to convert the initializer (at its location) and then
initialize the variable from the resulting prvalue.  If we instead
direct-initialize the variable, the location of the constructor call is that
of the variable.

gcc/cp/ChangeLog:

	* call.cc (convert_like_internal) [ck_user]: Use iloc_sentinel.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/srcloc17.C: Adjust initialization.
---
 gcc/cp/call.cc                        | 4 ++++
 gcc/testsuite/g++.dg/cpp2a/srcloc17.C | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)


base-commit: 2af87d98e66e57d51f36220de983eff44bae98c8
diff mbox series

Patch

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index d30f36d49ff..664088eed9c 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -8669,6 +8669,10 @@  convert_like_internal (conversion *convs, tree expr, tree fn, int argnum,
 	   rvalue, but we know it's read.  */
 	mark_exp_read (expr);
 
+	/* Give the conversion call the location of EXPR rather than the
+	   location of the context that caused the conversion.  */
+	iloc_sentinel ils (loc);
+
 	/* Pass LOOKUP_NO_CONVERSION so rvalue/base handling knows not to allow
 	   any more UDCs.  */
 	expr = build_over_call (cand, LOOKUP_NORMAL|LOOKUP_NO_CONVERSION,
diff --git a/gcc/testsuite/g++.dg/cpp2a/srcloc17.C b/gcc/testsuite/g++.dg/cpp2a/srcloc17.C
index a02ea487eef..4462038d588 100644
--- a/gcc/testsuite/g++.dg/cpp2a/srcloc17.C
+++ b/gcc/testsuite/g++.dg/cpp2a/srcloc17.C
@@ -90,7 +90,7 @@  bar ()
 	return false;
     }
 
-  S<N> e = __LINE__;
+  S<N> e (__LINE__);
   //   ^ column 8
   S<N> f = 1.0;
   if (cmp (e.loc.file_name (), file1))