[C++ PATCH] Preserve the location of explicitly defaulted functions.
Jason Merrill
jason@redhat.com
Fri Oct 11 18:57:00 GMT 2019
While working on operator<=> I noticed that a diagnostic referring to an
explicitly defaulted function was using the location of the class, rather than
the location of the declaration. We change DECL_SOURCE_LOCATION of implicitly
declared functions to indicate where they were first needed, but I don't want
to lose the location of actual declarations.
Tested x86_64-pc-linux-gnu, applying to trunk.
* decl2.c (mark_used): Don't clobber DECL_SOURCE_LOCATION on
explicitly defaulted functions.
* method.c (synthesize_method): Likewise.
---
gcc/cp/decl2.c | 3 ++-
gcc/cp/method.c | 7 ++++---
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index ee198cdf5ce..6d5e973b487 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -5588,7 +5588,8 @@ mark_used (tree decl, tsubst_flags_t complain)
/* Remember the current location for a function we will end up
synthesizing. Then we can inform the user where it was
required in the case of error. */
- DECL_SOURCE_LOCATION (decl) = input_location;
+ if (DECL_ARTIFICIAL (decl))
+ DECL_SOURCE_LOCATION (decl) = input_location;
/* Synthesizing an implicitly defined member function will result in
garbage collection. We must treat this situation as if we were
diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index 01bf534aef2..73a01147ff9 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -892,7 +892,7 @@ synthesize_method (tree fndecl)
/* Reset the source location, we might have been previously
deferred, and thus have saved where we were first needed. */
- if (!DECL_INHERITED_CTOR (fndecl))
+ if (DECL_ARTIFICIAL (fndecl) && !DECL_INHERITED_CTOR (fndecl))
DECL_SOURCE_LOCATION (fndecl)
= DECL_SOURCE_LOCATION (TYPE_NAME (DECL_CONTEXT (fndecl)));
@@ -953,8 +953,9 @@ synthesize_method (tree fndecl)
pop_deferring_access_checks ();
if (error_count != errorcount || warning_count != warningcount + werrorcount)
- inform (input_location, "synthesized method %qD first required here",
- fndecl);
+ if (DECL_ARTIFICIAL (fndecl))
+ inform (input_location, "synthesized method %qD first required here",
+ fndecl);
}
/* Build a reference to type TYPE with cv-quals QUALS, which is an
base-commit: 6dc6cd99d8bb4313585a1d9b93fc7a43fb2016a9
--
2.21.0
More information about the Gcc-patches
mailing list