aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/error.cc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2023-10-03 19:46:33 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2023-10-03 19:46:33 -0400
commit1c45319b66edc94e0de7b4c99104de4afa68e3ca (patch)
treef539fda16d57b11046fa780ac6b7a3e588cbaac2 /gcc/cp/error.cc
parent645f2a7dd47aa84d94df594bbd736085e51fc637 (diff)
downloadgcc-1c45319b66edc94e0de7b4c99104de4afa68e3ca.zip
gcc-1c45319b66edc94e0de7b4c99104de4afa68e3ca.tar.gz
gcc-1c45319b66edc94e0de7b4c99104de4afa68e3ca.tar.bz2
c++: print source code in print_instantiation_partial_context_line
As mentioned in my Cauldron talk, this patch adds a call to diagnostic_show_locus to the "required from here" messages in print_instantiation_partial_context_line, so that e.g., rather than the rather mystifying: In file included from ../x86_64-pc-linux-gnu/libstdc++-v3/include/memory:78, from ../../src/demo-1.C:1: ../x86_64-pc-linux-gnu/libstdc++-v3/include/bits/unique_ptr.h: In instantiation of ‘std::__detail::__unique_ptr_t<_Tp> std::make_unique(_Args&& ...) [with _Tp = bar; _Args = {}; __detail::__unique_ptr_t<_Tp> = __detail::__unique_ptr_t<bar>]’: ../../src/demo-1.C:15:32: required from here ../x86_64-pc-linux-gnu/libstdc++-v3/include/bits/unique_ptr.h:1066:30: error: no matching function for call to ‘bar::bar()’ 1066 | { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../src/demo-1.C:10:3: note: candidate: ‘bar::bar(int)’ 10 | bar (int); | ^~~ ../../src/demo-1.C:10:3: note: candidate expects 1 argument, 0 provided ../../src/demo-1.C:7:7: note: candidate: ‘constexpr bar::bar(const bar&)’ 7 | class bar : public foo | ^~~ ../../src/demo-1.C:7:7: note: candidate expects 1 argument, 0 provided ../../src/demo-1.C:7:7: note: candidate: ‘constexpr bar::bar(bar&&)’ ../../src/demo-1.C:7:7: note: candidate expects 1 argument, 0 provided we emit: In file included from ../x86_64-pc-linux-gnu/libstdc++-v3/include/memory:78, from ../../src/demo-1.C:1: ../x86_64-pc-linux-gnu/libstdc++-v3/include/bits/unique_ptr.h: In instantiation of ‘std::__detail::__unique_ptr_t<_Tp> std::make_unique(_Args&& ...) [with _Tp = bar; _Args = {}; __detail::__unique_ptr_t<_Tp> = __detail::__unique_ptr_t<bar>]’: ../../src/demo-1.C:15:32: required from here 15 | return std::make_unique<bar> (); | ~~~~~~~~~~~~~~~~~~~~~~^~ ../x86_64-pc-linux-gnu/libstdc++-v3/include/bits/unique_ptr.h:1066:30: error: no matching function for call to ‘bar::bar()’ 1066 | { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../src/demo-1.C:10:3: note: candidate: ‘bar::bar(int)’ 10 | bar (int); | ^~~ ../../src/demo-1.C:10:3: note: candidate expects 1 argument, 0 provided ../../src/demo-1.C:7:7: note: candidate: ‘constexpr bar::bar(const bar&)’ 7 | class bar : public foo | ^~~ ../../src/demo-1.C:7:7: note: candidate expects 1 argument, 0 provided ../../src/demo-1.C:7:7: note: candidate: ‘constexpr bar::bar(bar&&)’ ../../src/demo-1.C:7:7: note: candidate expects 1 argument, 0 provided which shows the code that's leading to the error (the bad call to std::make_unique). gcc/cp/ChangeLog: * error.cc (print_instantiation_partial_context_line): Call diagnostic_show_locus. gcc/testsuite/ChangeLog: * g++.dg/diagnostic/static_assert3.C: Add directives for additional source printing. * g++.dg/template/error60.C: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/cp/error.cc')
-rw-r--r--gcc/cp/error.cc2
1 files changed, 2 insertions, 0 deletions
diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc
index ef96e14..767478cf 100644
--- a/gcc/cp/error.cc
+++ b/gcc/cp/error.cc
@@ -3774,6 +3774,8 @@ print_instantiation_partial_context_line (diagnostic_context *context,
? _("recursively required from here\n")
: _("required from here\n"));
}
+ gcc_rich_location rich_loc (loc);
+ diagnostic_show_locus (context, &rich_loc, DK_NOTE);
}
/* Same as print_instantiation_full_context but less verbose. */