From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 5FE41385840D for ; Wed, 24 Apr 2024 19:18:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5FE41385840D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5FE41385840D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713986285; cv=none; b=v7gf+YTNIWIFI8pLG87YufzNNBAth+0WAFd8UX7xRU5OgjyzKV8oZnSdMq1S1Dle4h2UxQvZIJoQr9Aakv7DuQ3889TNrtvp6ucSnuQ9qOgNXxa3ergjKzA5yEbWBQgQmnA7lWMJaonj9+trh3kzu518vB3oSUhLN06zjM0NGl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713986285; c=relaxed/simple; bh=znWorrLgPIG5fMAt4gk9iAfXcEYYTYGT6M6pdO3sP9g=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=W+56TS1exIYyAKU1i0SYUGy+qkUp16sNCSYMi3TqbhzwUWAuc+Q6Ijmt4OjoE4JCuU8jz/Qvak0BIPaq9kd5GZuF755rI78WzhPPPPOqxL3XME3RJHT9N/rb7RPqgNNtApN/URjQJvYiSGgvanNZKz9TiVwZaEu0sTvBxz573Iw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713986281; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6U3+F1OUojIhyOmCIySp5aVGJ1DDhGFjc0g7dUiGvMY=; b=E5JSru7VYwirnjxic/mogmPpxSY7OqTi2OUmwgoh/uoQ8nV+3MUbXZZ0f026+1d+ikUVMO 2FNQGjo5mh7pXxL5/y6ydR8boJd9b8nPP128CBb1tCUWiw/DlBRwKQ6mCnDEgPzGJdZa5Y /t5wcJlo95tP9AjpPNXanDwxa+oIQ5M= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-631-PUDaNeBnMOWIU9OtK248OQ-1; Wed, 24 Apr 2024 15:18:00 -0400 X-MC-Unique: PUDaNeBnMOWIU9OtK248OQ-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-69937a7ea21so2722286d6.3 for ; Wed, 24 Apr 2024 12:18:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713986279; x=1714591079; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TUVh6kAsziUw7h8PGYmAmAhJbu//LwDcJB/XogDqags=; b=wYSmOvIxHmFZHmGyy1DtTDG7meZo8Lg4uZQ5pofw67BxAS1ZRsBwriq3HIdF2p+QEl esLeGAqOc9JJB/09ELlijguVX4YjjqjO/oZXHTgT2W+9qRtfbp+VsEo5bgNozjuoDdhI ueV6gltyRmNpc8MdzAXCrJebwqmEWF7SyDI2nExFHpNg7cmcZ5BoYYGLdrds4yOczi8b S65eugXQBjqtDW9LkJthwZlKK7BOCTBEXZgDIwYc0X5YVt29uipFgKF63/QCe1Jh4cbO 8p0TnwYiBgW3cj+XAQNpEKTZ0L8CVTrI/Smnk4QFwRaeo5+XLlujcdtmyB2j284EK5oP PKbA== X-Forwarded-Encrypted: i=1; AJvYcCW7MUzrBPMwkQ9pJAZzFVIjs3f4qRmleJcRD5peFx9VvlcspgOVGQEFTHxTIeWxzOAvC2UWc05jyBS2mQaIOd32S1aAaT336A== X-Gm-Message-State: AOJu0Yy9KHfP5mJgMNJxgWby32lVxhodEchHmU8hZghOBOo96QnHxpEB ceuE2fEXRwsTHGLfghDueRft3puU+2JMy8etgIoI3/lk4HQaamfPzKX1fUQ12TaLGl0eWt+Ogee DjdNx9ZuAKhfy0gRDrJoOL33t9a+QjmxGK7lND31zvuHM8x0FHR8XsI8= X-Received: by 2002:ad4:5110:0:b0:69b:81c5:3b68 with SMTP id g16-20020ad45110000000b0069b81c53b68mr3337836qvp.36.1713986279324; Wed, 24 Apr 2024 12:17:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4ELE4xCY+Bx09CK51M/OqF+QCtV64eEtNHVGf3j/DIdzq+a25B2MI16sL3sb/VqLBfIh0mQ== X-Received: by 2002:ad4:5110:0:b0:69b:81c5:3b68 with SMTP id g16-20020ad45110000000b0069b81c53b68mr3337814qvp.36.1713986278904; Wed, 24 Apr 2024 12:17:58 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id j13-20020a0c9ccd000000b00696ae38c7bfsm3051984qvf.35.2024.04.24.12.17.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 12:17:58 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Wed, 24 Apr 2024 15:17:57 -0400 (EDT) To: Patrick Palka cc: David Malcolm , gcc-patches@gcc.gnu.org, Jason Merrill Subject: Re: [PATCH] c++: print source code in print_instantiation_partial_context_line In-Reply-To: <19f955ec-c497-0f11-44af-eebed9702210@idea> Message-ID: <1c0eb371-d3c3-762b-9595-b5b4e9aaeba5@idea> References: <20231003164812.13294-1-dmalcolm@redhat.com> <97fee3fd-40ec-dc65-9ca1-daf991cb09db@idea> <19f955ec-c497-0f11-44af-eebed9702210@idea> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="8323329-777349401-1713986278=:3760645" X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-777349401-1713986278=:3760645 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT On Tue, 9 Apr 2024, Patrick Palka wrote: > On Thu, 19 Oct 2023, Patrick Palka wrote: > > > On Tue, 3 Oct 2023, David Malcolm wrote: > > > > > 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]’: > > > ../../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]’: > > > ../../src/demo-1.C:15:32: required from here > > > 15 | return std::make_unique (); > > > | ~~~~~~~~~~~~~~~~~~~~~~^~ > > > ../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). > > > > This is great! I noticed however that the source code gets printed in a > > surprising way in some contexts. Consider: > > > > template void f(typename T::type); > > > > int main() { > > f(0); > > } > > > > For this testcase we emit: > > > > testcase.C: In function ‘int main()’: > > testcase.C:4:9: error: no matching function for call to ‘f(int)’ > > 4 | f(0); > > | ~~~~~~^~~ > > testcase.C:1:24: note: candidate: ‘template void f(typename T::type)’ > > 1 | template void f(typename T::type); > > | ^ > > testcase.C:1:24: note: template argument deduction/substitution failed: > > testcase.C: In substitution of ‘template void f(typename T::type) [with T = int]’: > > testcase.C:4:9: required from here > > testcase.C:1:24: note: 4 | f(0); > > testcase.C:1:24: note: | ~~~~~~^~~ > > testcase.C:1:24: error: ‘int’ is not a class, struct, or union type > > 1 | template void f(typename T::type); > > | ^ > > > > In particular the source code part following the "required from here" line > > > > testcase.C:4:9: required from here > > testcase.C:1:24: note: 4 | f(0); > > testcase.C:1:24: note: | ~~~~~~^~~ > > > > seems off, I would have expected it be > > > > testcase.C:4:9: required from here > > 4 | f(0); > > | ~~~~~~^~~ > > > > i.e. without the "testcase.C:1:24: note: " prefix. Does this look > > expected? (I also wonder if we might want to omit printing the source > > code altogether in this case, since we already printed that same line > > earlier during the "no matching function" error?) > > Sorry for forgetting to ping this earlier, but I wonder what if anything > we should do about this for GCC 14? Here's another example of the source code rendering issue using a test from the libstdc++ testsuite: $ g++ -D_GLIBCXX_DEBUG -Wsystem-headers -Wsign-compare -std=c++23 -I libstdc++-v3/testsuite/util libstdc++-v3/testsuite/std/ranges/adaptors/enumerate/1.cc In file included from /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/version.h:49, from /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/concepts:36, from /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/ranges:37, from libstdc++-v3/testsuite/std/ranges/adaptors/enumerate/1.cc:4: /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc: In instantiation of ‘constexpr void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::resize_and_overwrite(size_type, _Operation) [with _Operation = std::__format::__formatter_fp::format >(float, std::basic_format_context, wchar_t>&) const::&; _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; size_type = long unsigned int]’: [ ... snip ... ] /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/format:4038:23: required from ‘constexpr void std::__format::_Formatting_scanner<_Out, _CharT>::_M_format_arg(std::size_t) [with _Out = std::__format::_Sink_iter; _CharT = wchar_t; std::size_t = long unsigned int]’ 4038 | std::visit_format_arg([this](auto& __arg) { | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ 4039 | using _Type = remove_reference_t; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4040 | using _Formatter = typename _Context::template formatter_type<_Type>; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4041 | if constexpr (is_same_v<_Type, monostate>) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4042 | __format::__invalid_arg_id_in_format_string(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4043 | else if constexpr (is_same_v<_Type, handle>) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4044 | __arg.format(this->_M_pc, this->_M_fc); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4045 | else if constexpr (is_default_constructible_v<_Formatter>) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4046 | { | ~ 4047 | _Formatter __f; | ~~~~~~~~~~~~~~~ 4048 | this->_M_pc.advance_to(__f.parse(this->_M_pc)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4049 | this->_M_fc.advance_to(__f.format(__arg, this->_M_fc)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4050 | } | ~ 4051 | else | ~~~~ 4052 | static_assert(__format::__formattable_with<_Type, _Context>); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4053 | }, _M_fc.arg(__id)); | ~~~~~~~~~~~~~~~~~~~ /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/format:4033:7: required from here 4033 | _M_format_arg(size_t __id) override | ^~~~~~~~~~~~~ /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: comparison of integer expressions of different signedness: ‘long int’ and ‘const std::__cxx11::basic_string::size_type’ {aka ‘const long unsigned int’} [-Wsign-compare] 609 | _GLIBCXX_DEBUG_ASSERT(__r >= 0 && __r <= __n); | ^~~~~~~~~~~~~~~~~~~~~ /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc: In instantiation of ‘constexpr void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::resize_and_overwrite(size_type, _Operation) [with _Operation = std::__format::__formatter_fp::format >(double, std::basic_format_context, wchar_t>&) const::&; _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; size_type = long unsigned int]’: [ ... snip ... ] /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/format:4038:23: required from ‘constexpr void std::__format::_Formatting_scanner<_Out, _CharT>::_M_format_arg(std::size_t) [with _Out = std::__format::_Sink_iter; _CharT = wchar_t; std::size_t = long unsigned int]’ /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: 4038 | std::visit_format_arg([this](auto& __arg) { /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ 4039 | using _Type = remove_reference_t; /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4040 | using _Formatter = typename _Context::template formatter_type<_Type>; /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4041 | if constexpr (is_same_v<_Type, monostate>) /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4042 | __format::__invalid_arg_id_in_format_string(); /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4043 | else if constexpr (is_same_v<_Type, handle>) /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4044 | __arg.format(this->_M_pc, this->_M_fc); /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4045 | else if constexpr (is_default_constructible_v<_Formatter>) /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4046 | { /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: | ~ 4047 | _Formatter __f; /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: | ~~~~~~~~~~~~~~~ 4048 | this->_M_pc.advance_to(__f.parse(this->_M_pc)); /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4049 | this->_M_fc.advance_to(__f.format(__arg, this->_M_fc)); /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4050 | } /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: | ~ 4051 | else /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: | ~~~~ 4052 | static_assert(__format::__formattable_with<_Type, _Context>); /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4053 | }, _M_fc.arg(__id)); /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: | ~~~~~~~~~~~~~~~~~~~ /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/format:4033:7: required from here /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: 4033 | _M_format_arg(size_t __id) override /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: | ^~~~~~~~~~~~~ /scratchpad/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609:7: warning: comparison of integer expressions of different signedness: ‘long int’ and ‘const std::__cxx11::basic_string::size_type’ {aka ‘const long unsigned int’} [-Wsign-compare] 609 | _GLIBCXX_DEBUG_ASSERT(__r >= 0 && __r <= __n); | ^~~~~~~~~~~~~~~~~~~~~ [ ... snip ... ] The instantiation context source code for the first warning get rendered fine, but for subsequent warnings they contain a spurious "file:line:col: warning: " prefix which seems to be inherited from the warning before it. > > > > > > > > > > > > Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. > > > > > > OK for trunk? > > > > > > > > > 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 > > > --- > > > gcc/cp/error.cc | 2 + > > > .../g++.dg/diagnostic/static_assert3.C | 7 +++- > > > gcc/testsuite/g++.dg/template/error60.C | 37 +++++++++++++++++++ > > > 3 files changed, 45 insertions(+), 1 deletion(-) > > > create mode 100644 gcc/testsuite/g++.dg/template/error60.C > > > > > > diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc > > > index ef96e140f24..767478cf5fd 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. */ > > > diff --git a/gcc/testsuite/g++.dg/diagnostic/static_assert3.C b/gcc/testsuite/g++.dg/diagnostic/static_assert3.C > > > index 5d363884508..4ec53f17120 100644 > > > --- a/gcc/testsuite/g++.dg/diagnostic/static_assert3.C > > > +++ b/gcc/testsuite/g++.dg/diagnostic/static_assert3.C > > > @@ -5,6 +5,11 @@ > > > template struct is_same { static constexpr bool value = false; }; > > > template struct is_same { static constexpr bool value = true; }; > > > > > > +/* { dg-begin-multiline-output "" } > > > + f(0, 1.3); > > > + ~^~~~~~~~ > > > + { dg-end-multiline-output "" } */ > > > + > > > template > > > void f(T, U) > > > { > > > @@ -32,5 +37,5 @@ void f(T, U) > > > > > > void g() > > > { > > > - f(0, 1.3); > > > + f(0, 1.3); // { dg-message " required from here" } > > > } > > > diff --git a/gcc/testsuite/g++.dg/template/error60.C b/gcc/testsuite/g++.dg/template/error60.C > > > new file mode 100644 > > > index 00000000000..8c2139b207c > > > --- /dev/null > > > +++ b/gcc/testsuite/g++.dg/template/error60.C > > > @@ -0,0 +1,37 @@ > > > +// { dg-options "-fdiagnostics-show-caret" } > > > + > > > +template > > > +struct my_pointer > > > +{ > > > + my_pointer (Foo *ptr) // { dg-message " initializing argument 1" } > > > + : m_ptr (ptr) > > > + {} > > > + > > > + Foo *m_ptr; > > > +}; > > > + > > > +template > > > +void test (Foo val) > > > +{ > > > + my_pointer ptr (val); // { dg-error "invalid conversion from 'int' to 'int\\*'" } > > > +} > > > + > > > +void usage () > > > +{ > > > + test (42); // { dg-message " required from here" } > > > + /* { dg-begin-multiline-output "" } > > > + test (42); > > > + ~~~~~~~~~~^~~~ > > > + { dg-end-multiline-output "" } */ > > > +} > > > + > > > + /* { dg-begin-multiline-output "" } > > > + my_pointer (Foo *ptr) > > > + ~~~~~^~~ > > > + { dg-end-multiline-output "" } */ > > > + /* { dg-begin-multiline-output "" } > > > + my_pointer ptr (val); > > > + ^~~ > > > + | > > > + int > > > + { dg-end-multiline-output "" } */ > > > -- > > > 2.26.3 > > > > > > --8323329-777349401-1713986278=:3760645--