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 E82B33858D39 for ; Tue, 9 Apr 2024 19:41:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E82B33858D39 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 E82B33858D39 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=1712691710; cv=none; b=P3qSF2l5LQQGMlnW+WTVi0lcbMXV99ZmqLLUWcFXi06YzLCpmk1TizcAMAdG/eMqrJeJbVwRLRDxG8dcvpICEY1nzZ6g/WlkpjvEBMRUGqKbK46mpJknb6QboPV15xXlmGNnMoqP0L1D6wd2XXCmBUmRHFmjuTWSoVVo6KjzY6w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712691710; c=relaxed/simple; bh=tm9nNNj5L6QvxAuNmf1SttQ3+JK2sDi+ygn5JjRrbBM=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=U3cbVJDDZNVY1RaxaZ9zlcDJDXnxvz5YYxB0NA6j/dZ+s4MfMGbGhIcZ233d4pGbIXXpfMxaCOXrqrZFiipyOtUSb0sap47VGaNzSmoIQwEIJ1tAFmmiAMCV6DFdsuzAOO8uYOaqmvzuXHAg+IbtNAmyi9syENkw7SWFrLq0Fn4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712691708; 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=I/Rpn6FWbL5033hZx8d247xLcBsoj0i5s7Emt+211LE=; b=Yg1W8zdG9u98dxLMhICaoTejwVh1qyP4eyPCmV8vY7xn8nim6GqX+mXAVJA04Pg+NtKkOA pprJAv6+DO1YSVyeLs1EAXuYjtPc3MZ1uzkkdrKg28hXh1IjRlNPrwUs4eqPd/aQ67Jl2R Cpq3841IkujlIZyz8FT8x2ZTxSONZVk= 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-625-aKEsORGON0KLg7GjSrzo7Q-1; Tue, 09 Apr 2024 15:41:46 -0400 X-MC-Unique: aKEsORGON0KLg7GjSrzo7Q-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-698f85bf400so50690666d6.3 for ; Tue, 09 Apr 2024 12:41:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712691706; x=1713296506; 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=7oMWExRLzgygPw/kk5RUD5OlLLPSC8PDFL1YvH+2QA8=; b=j0URO8KAu9lcKNXP1yaklb/6UmDHWrGcnsE6U0oHv9pDBcRfXFjv4Qqlweid3B+OK5 ucszlLeoAc9cX1lLEn4/jsF125hGzyND8//RF0anJIeY6uyxUHjLnVgMVGgqeGsfHe0m LP3b8h2shCfmNCbRTzOB4mEzXhyzcrSbGDmSVSYmO5D84dsIX11CFtETOGlVt3XVfyfj 7VSb2ak8qjLiqyMcXLtxdeZo8GXee06ihzArXOSfWl+GxC2yp/xYjP98a5w7LD9A/BGv uU15/pfSSb54xOA48fkZiyoGEZ3054dEtDVVzvQT+Ajzgh7r+ep4ZFHIk4HZLez5Qf+d Eg4w== X-Forwarded-Encrypted: i=1; AJvYcCWpCnfUo3u2tAyLIeePnMH+Ii4LluURY4KmXB5FTnHaZF06EGCedzz8xlD81dwCDA3gleXYo7WbaQxP9MmvXB4V8+FxjPHDZg== X-Gm-Message-State: AOJu0YzmTtHxbHtK7I3XK7xef5PzoYC1a2IfAkY2MJ8dXx4AEpsP1Wao Nsx8pfv8DKGh8lvgPWBGu/ceQftGQ+QlOYyFXbNNtGApr/A8VljVis4+3pn5EQSZE+CJOtJvqw7 0yYcgmYr573JmlWUhg/JaRPleI7XJrnFJcHbou8/IU53WL7U6pgSZX8Q= X-Received: by 2002:a05:6214:2a47:b0:69b:135c:5140 with SMTP id jf7-20020a0562142a4700b0069b135c5140mr430215qvb.52.1712691706159; Tue, 09 Apr 2024 12:41:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFq66PI4pGsiRkaKXEJhftUQmQPYC1i9+HcA/XV7bayB/06cwYhISBC6eGOuURL/NU7h5nvjQ== X-Received: by 2002:a05:6214:2a47:b0:69b:135c:5140 with SMTP id jf7-20020a0562142a4700b0069b135c5140mr430203qvb.52.1712691705718; Tue, 09 Apr 2024 12:41:45 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id eu13-20020ad44f4d000000b006993b11ad01sm4264363qvb.75.2024.04.09.12.41.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 12:41:45 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Tue, 9 Apr 2024 15:41:44 -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: <97fee3fd-40ec-dc65-9ca1-daf991cb09db@idea> Message-ID: <19f955ec-c497-0f11-44af-eebed9702210@idea> References: <20231003164812.13294-1-dmalcolm@redhat.com> <97fee3fd-40ec-dc65-9ca1-daf991cb09db@idea> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="8323329-2131953568-1712691705=:3760645" X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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-2131953568-1712691705=:3760645 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT 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? > > > > > > > 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-2131953568-1712691705=:3760645--