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 253893858416 for ; Thu, 25 Apr 2024 18:48:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 253893858416 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 253893858416 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=1714070934; cv=none; b=Fafcc4ntwyAaXeQOHXuKvg88s/Rke6umMcMeSumx+xFiEbSxOwnrnKm8evv0z71ZEjRBHmRb9kUCgtmpYE77ts8XVXcEGsO9alRxaweNHJ2eL/uCvIIbKs0JoEwFEezTrd3FjZoKqpFWe0CLFU1Ge2RuAN9ECyypmdrbKaAp6BQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714070934; c=relaxed/simple; bh=j6x1Hie3cuaafsBYsO8bun262ehh6X17QMB4Q6Dthl4=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=miD8s6xFgeiob+g2adgooZwOZTOBJNL3CQazx6EPY1FkrFvCthyi+4gxbV7OwzdDBOCQkRuB0QIqihBhyCja/ymAMjyPkheRxlIcvOMGtLAvd5VlWgAaHUALXnXvvTXEgkD4ucJtDt6ISz6inOT9d31qT+R7/rs0Wpi2B0PqdT0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714070931; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sd7VctewepSZkvs6J2/Qh9zPOeIj+uOcqmrappQ4c+o=; b=InDiyVa5U331QSWqtKPo23RhkdZaKrgNqDVC6sPXBOIa2sssNHTG+suOvSjmUAm6wCn48X 80aVbCH0uce0u1LGdRjaIyMrTPthoYVb1k1NJ/7HrCxjS4nNsX/dkFRDBfFytI6TsGqWFq iBkM0YpYWwvciCjMaTR7atEnAULgc9k= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-251-RoWDGI1hNq-PqOI-BseBzA-1; Thu, 25 Apr 2024 14:48:48 -0400 X-MC-Unique: RoWDGI1hNq-PqOI-BseBzA-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-43a2aab079cso15605301cf.1 for ; Thu, 25 Apr 2024 11:48:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714070926; x=1714675726; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=sd7VctewepSZkvs6J2/Qh9zPOeIj+uOcqmrappQ4c+o=; b=BBU8nIQH/zy7rBPQvWyOg1+jKRcG4qBG3i+mNvz36QfCdh3EtB95VueRGDKckrkssm C7B6Ha2o2zX8aT9NtGeoHPIH82+gCj7bNcV8P/+BljkBtw0CZRndyVok17/WOb6KYPKv VcJmSnTL/k0ffAsVkgglZYGI60A343WXGLPV9NRdKE8367SsR1Sg3Ih/RRoAxbEvM/iX N/u+YuaLVEkHuITfwSx4OEXp8vn+JpCtzXisV8RH/Akp/B2Dgj1K5u4nFtPRTXHep4ME svdv0M7cZUsiTum9g2Np7mAaYmGloHHw3yv9MIeI+IbSZ+/6cFnYy1tOjWfjJhbswLne U/TA== X-Gm-Message-State: AOJu0Yy94dmUt5pnXE+JLyIgesSQAvhWLqx9OfTkTq6FZH5Nd8kGjt1Q RpW5RmZnVNSBQi8DfsYFb0ABE8u7lxhn75sRe/XcqW25kb1t0A1aKBWAj4Ge3NqiNw7Ezv7KqP0 KKnmQNDvkVSzomXICZfy3JsfI9PFp/LAyth67bBRIUbpYFfavgu/p8q4= X-Received: by 2002:ac8:5a4b:0:b0:43a:169c:f808 with SMTP id o11-20020ac85a4b000000b0043a169cf808mr645297qta.28.1714070926396; Thu, 25 Apr 2024 11:48:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVAYNvoeR4ypMisf7FkUpBvRieQak54wCfgelQKl4KyIRx1W8WzCKZiZyKn4VF8Ae4q9EVAQ== X-Received: by 2002:ac8:5a4b:0:b0:43a:169c:f808 with SMTP id o11-20020ac85a4b000000b0043a169cf808mr645272qta.28.1714070925942; Thu, 25 Apr 2024 11:48:45 -0700 (PDT) Received: from t14s.localdomain (c-76-28-97-5.hsd1.ma.comcast.net. [76.28.97.5]) by smtp.gmail.com with ESMTPSA id kf22-20020a05622a2a9600b00434a041d310sm7190791qtb.16.2024.04.25.11.48.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 11:48:45 -0700 (PDT) Message-ID: <4a899c6796eec17186918f9ffb116b1ed642caa4.camel@redhat.com> Subject: Re: [PATCH] c++: fix source printing for "required from here" message From: David Malcolm To: Patrick Palka , Jason Merrill Cc: gcc-patches@gcc.gnu.org Date: Thu, 25 Apr 2024 14:48:44 -0400 In-Reply-To: <5930feb9-9460-457f-70c4-09c2c662d79e@idea> References: <20240424202206.173103-1-ppalka@redhat.com> <8bcaf757-d1fe-4ea5-8128-77b6fbf465e3@redhat.com> <5930feb9-9460-457f-70c4-09c2c662d79e@idea> User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00,BODY_8BITS,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,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 Wed, 2024-04-24 at 17:05 -0400, Patrick Palka wrote: > On Wed, 24 Apr 2024, Jason Merrill wrote: >=20 > > On 4/24/24 13:22, Patrick Palka wrote: > > > Tested on x86_64-pc-linux-gnu, full bootstrap+regtest in > > > progress, > > > does this look OK if successful? > > >=20 > > > -- >8 -- > > >=20 > > > It seems the diagnostic machinery's source line printing respects > > > the pretty printer prefix, but this is undesirable for the call > > > to > > > diagnostic_show_locus in print_instantiation_partial_context_line > > > added in r14-4388-g1c45319b66edc9 since the prefix may have been > > > set when issuing an earlier, unrelated diagnostic and we just > > > want > > > to print an unprefixed source line. > > >=20 > > > This patch naively fixes this by clearing the prefix before > > > calling > > > diagnostic_show_locus. > > >=20 > > > Before this patch, for error60a.C below we'd print > > >=20 > > > gcc/testsuite/g++.dg/template/error60a.C: In function =E2=80=98void > > > usage()=E2=80=99: > > > gcc/testsuite/g++.dg/template/error60a.C:24:3: error: > > > =E2=80=98unrelated_error=E2=80=99 was > > > not declared in this scope > > > =C2=A0=C2=A0=C2=A0 24 |=C2=A0=C2=A0 unrelated_error; // { dg-error "n= ot declared" } > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 ^~~~~~~~~~~~~~~ > > > gcc/testsuite/g++.dg/template/error60a.C: In instantiation of > > > =E2=80=98void > > > test(Foo) [with Foo =3D int]=E2=80=99: > > > gcc/testsuite/g++.dg/template/error60a.C:25:13:=C2=A0=C2=A0 required = from > > > here > > > gcc/testsuite/g++.dg/template/error60a.C:24:3: error:=C2=A0=C2=A0=C2= =A0 25 |=C2=A0=C2=A0 > > > test > > > (42); // { dg-message " required from here" } > > > gcc/testsuite/g++.dg/template/error60a.C:24:3: error:=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 | > > > ~~~~~~~~~~^~~~ > > > gcc/testsuite/g++.dg/template/error60a.C:19:24: error: invalid > > > conversion > > > from =E2=80=98int=E2=80=99 to =E2=80=98int*=E2=80=99 [-fpermissive] > > > =C2=A0=C2=A0=C2=A0 19 |=C2=A0=C2=A0 my_pointer ptr (val); // { d= g-error "invalid > > > conversion from > > > 'int' to 'int\\*'" } > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ^~~ > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int > > > gcc/testsuite/g++.dg/template/error60a.C:9:20: note:=C2=A0=C2=A0 > > > initializing argument > > > 1 of =E2=80=98my_pointer::my_pointer(Foo*) [with Foo =3D int]=E2= =80=99 > > > =C2=A0=C2=A0=C2=A0=C2=A0 9 |=C2=A0=C2=A0 my_pointer (Foo *ptr) // { d= g-message " initializing > > > argument 1" > > > } > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ~~~~~^~~ > > >=20 > > > and afterward we print > > >=20 > > > gcc/testsuite/g++.dg/template/error60a.C: In function =E2=80=98void > > > usage()=E2=80=99: > > > gcc/testsuite/g++.dg/template/error60a.C:24:3: error: > > > =E2=80=98unrelated_error=E2=80=99 was > > > not declared in this scope > > > =C2=A0=C2=A0=C2=A0 24 |=C2=A0=C2=A0 unrelated_error; // { dg-error "n= ot declared" } > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 ^~~~~~~~~~~~~~~ > > > gcc/testsuite/g++.dg/template/error60a.C: In instantiation of > > > =E2=80=98void > > > test(Foo) [with Foo =3D int]=E2=80=99: > > > gcc/testsuite/g++.dg/template/error60a.C:25:13:=C2=A0=C2=A0 required = from > > > here > > > =C2=A0=C2=A0=C2=A0 25 |=C2=A0=C2=A0 test (42); // { dg-message "= required from here" > > > } > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 ~~~~~~~~~~^~~~ > > > gcc/testsuite/g++.dg/template/error60a.C:19:24: error: invalid > > > conversion > > > from =E2=80=98int=E2=80=99 to =E2=80=98int*=E2=80=99 [-fpermissive] > > > =C2=A0=C2=A0=C2=A0 19 |=C2=A0=C2=A0 my_pointer ptr (val); // { d= g-error "invalid > > > conversion from > > > 'int' to 'int\\*'" } > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ^~~ > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int > > > gcc/testsuite/g++.dg/template/error60a.C:9:20: note:=C2=A0=C2=A0 > > > initializing argument > > > 1 of =E2=80=98my_pointer::my_pointer(Foo*) [with Foo =3D int]=E2= =80=99 > > > =C2=A0=C2=A0=C2=A0=C2=A0 9 |=C2=A0=C2=A0 my_pointer (Foo *ptr) // { d= g-message " initializing > > > argument 1" > > > } > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ~~~~~^~~ > > >=20 > > > gcc/cp/ChangeLog: > > >=20 > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* error.cc (print_ins= tantiation_partial_context_line): > > > Clear > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0context->printer->pre= fix around the call to > > > diagnostic_show_locus. > > >=20 > > > gcc/testsuite/ChangeLog: > > >=20 > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* g++.dg/concepts/dia= gnostic2.C: Expect source line > > > printed > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0for the required from= here message. > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* g++.dg/template/err= or60a.C: New test. > > > --- > > > =C2=A0 gcc/cp/error.cc=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 2 + > > > =C2=A0 gcc/testsuite/g++.dg/concepts/diagnostic2.C |=C2=A0 6 ++- > > > =C2=A0 gcc/testsuite/g++.dg/template/error60a.C=C2=A0=C2=A0=C2=A0 | 4= 6 > > > +++++++++++++++++++++ > > > =C2=A0 3 files changed, 53 insertions(+), 1 deletion(-) > > > =C2=A0 create mode 100644 gcc/testsuite/g++.dg/template/error60a.C > > >=20 > > > diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc > > > index 7074845154e..a7067d4d2ed 100644 > > > --- a/gcc/cp/error.cc > > > +++ b/gcc/cp/error.cc > > > @@ -3793,7 +3793,9 @@ print_instantiation_partial_context_line > > > (diagnostic_context *context, > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 : _("required from here\n")); > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > > > =C2=A0=C2=A0=C2=A0 gcc_rich_location rich_loc (loc); > > > +=C2=A0 char *saved_prefix =3D pp_take_prefix (context->printer); > > > =C2=A0=C2=A0=C2=A0 diagnostic_show_locus (context, &rich_loc, DK_NOTE= ); > > > +=C2=A0 context->printer->prefix =3D saved_prefix; > >=20 > > I would follow the pattern of c_diagnostic_finalizer here, i.e. > > using > > pp_set_prefix for the restore. >=20 > FWIW that's what I originally went with, but I don't really > understand > the other things pp_set_prefix does besides setting the prefix and > then I noticed cp_print_error_function restores ->prefix directly so > I ended up doing that instead. I have a slight preference for using pp_set_prefix for the restore, but the patch as written is also OK; thanks. I confess that I don't have a strong sense of how the prefix code is meant to work. It seems to be for use with this combination of options: -fmessage-length=3DNON_ZERO -fdiagnostics-show-location=3Devery-line which triggers line-wrapping, adding the prefix at each line when line wrapping occurs. This seems to have existed at least as far back as=20 856b62442f6fc5e4302ae9ee1ebce8a19bbd8681 re this "C++ err msgs" thread from 2000: https://gcc.gnu.org/pipermail/libstdc++/2000-May/004650.html https://gcc.gnu.org/pipermail/libstdc++/2000-May/004664.html https://gcc.gnu.org/pipermail/gcc-patches/2000-May/031143.html which made the prefixing optional on continuation lines. I suspect that if anyone was using that combination of options, we've probably broken it at some point with quoting of source code, underlining, fix-it hints, etc etc Dave >=20 > >=20 > > Though I think the pp_set_prefix to NULL in c_diagnostic_finalizer > > is > > redundant and should have been removed in r9-2240-g653fee1961981f > > when the > > previous line changed from _set_ to _take_.=C2=A0 If it isn't redundant= , > > then it > > should be, i.e. pp_take_prefix should call it instead of directly > > setting > > NULL. > >=20 > > Some _take_ callers do set(NULL) and others don't; they should > > definitely be > > consistent one way or the other. > >=20 > > David, what do you think? > >=20 > > Jason > >=20