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 8D4583858296 for ; Tue, 3 Oct 2023 21:10:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8D4583858296 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696367457; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a/ebdU1/2GUWfYTdNaebi9a079uylOxNZrncYrxppAk=; b=JVEFCoCzhpwCdAaYwDAIen7qj6/64zDOq4P6rPtn07Jx3EgTj90Th0O+skAfIeLHE5Ib8X vKtYVwG+RKwUyCrueR+z59VRgNXtIw7wZtPKafZCxOxwA7q1I4nOkgpZSHVsj3W76jfmk0 npmkVyORcMNZmM0WRkBSj86lBTRPRuU= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-75-vPqAjU1DNzebTj9ZrF9XOA-1; Tue, 03 Oct 2023 17:10:55 -0400 X-MC-Unique: vPqAjU1DNzebTj9ZrF9XOA-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-419923ea68cso15826241cf.1 for ; Tue, 03 Oct 2023 14:10:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696367455; x=1696972255; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=a/ebdU1/2GUWfYTdNaebi9a079uylOxNZrncYrxppAk=; b=PoEvhmyvhhTkXHHiYMQFMeUaOKidQn5H2vKBlBvzmzvqjZhm/TpNQyNrG9DFNPadgW 1qN2V78bYFPAPTSjaDdwUKPaekwPTc6tc+Yv6ZyEKk6zFzfTm0mYYLrAH7VXKTsCWckE ItrTu/IjeYDZLFQP/PTyuV5oDeGkCb28dEc9Ch3RWFLmehwXD3Ntz5xLcSC2TX8fVL+u 5O8YVsjwItdUvUR5RdBbY0yDjXenmNcOzoxOuQlONxMtKMWrhGGlga977SDP1d7LVkvt cKxAtgvBq+T6psMwILEgRT94KFkBX/9tvUJYLm5M3nKdfus5WRwJv33s8uPJYQ0LiB3t hCDg== X-Gm-Message-State: AOJu0YxmujSbgtxTguZxVbbQsCoAbqoywAy+DXLLGTjqOKKHwKhc01Pb pUx4B4A3oGkKuLmhAgJ7YXBx14dG5JFz1hVcAKbABYo4nCQfKq1iiFeluw/t+QoHkOGxEf4qima RU1RcC8pF5KOTHVyUPQ== X-Received: by 2002:a05:622a:1827:b0:401:e2bb:e423 with SMTP id t39-20020a05622a182700b00401e2bbe423mr648329qtc.55.1696367454792; Tue, 03 Oct 2023 14:10:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH+O0cI+L8gnDYZIhWwWdI1G+sZ7uMXK/16jp1674xF9CE6tN3smYwTmXyRkfALwZ/IyUGyBw== X-Received: by 2002:a05:622a:1827:b0:401:e2bb:e423 with SMTP id t39-20020a05622a182700b00401e2bbe423mr648314qtc.55.1696367454343; Tue, 03 Oct 2023 14:10:54 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id jx9-20020a05622a810900b0041812703b7esm739149qtb.52.2023.10.03.14.10.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Oct 2023 14:10:53 -0700 (PDT) Message-ID: Date: Tue, 3 Oct 2023 17:10:52 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: print source code in print_instantiation_partial_context_line To: David Malcolm , gcc-patches@gcc.gnu.org References: <20231003164812.13294-1-dmalcolm@redhat.com> From: Jason Merrill In-Reply-To: <20231003164812.13294-1-dmalcolm@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.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: On 10/3/23 12:48, 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). > > > Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. > > OK for trunk? OK, thanks. Now that you mention it, that's long been a small annoyance that never quite reached the point that it occurred to me to fix it. Jason > > 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 "" } */