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.133.124]) by sourceware.org (Postfix) with ESMTPS id 9113F384640E for ; Wed, 24 Apr 2024 21:05:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9113F384640E 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 9113F384640E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713992755; cv=none; b=gKuQLuKtMXlinEZ+xhubOOsBha04dMwuVbLIJxOwi1MFKvBEZ35uX56WPzdscfGBpUd44NvXnaq1pbsnmTfuwe6Eta9DAK/DFnzqVXxEagNB4P6SBjjz8RjLdhPcv3xSjKbjRTua7zxnSycHuLWpBJ/IVcA1Zj9n+HlR9PhTdpM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713992755; c=relaxed/simple; bh=hxkVlC/nSWYkGFCqhOfaGaqkmYp8T17m/LzMzL0/B/s=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=FQRrKFQ+vWsbLefrzQk8tR2BnFA2wH4P/1+eVylN+eVsM59e62jjxnP8sBa10qIBjTWavnqOHjbIkm2mDKAz6TbFQPfdpIXxS6zYrTDgAAosipMFCKWteQh+JyH2TIkyvaxzIY8QKrw+1ceObSmxZQ8Qsqxl7hDNBnYhy+Qux8c= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713992751; 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=C07XTw0Cm7p7m28QBx8uQL5xAPk+yl8J/hlBvp7jWnM=; b=Zen5gKaZCdtvv7GldkhhWCX/1Wes653fE2tzkgU+b3pGSvhgw525s+0Fjl8mxuS4YcMR7/ cf0Xd7oAXgqEZRqkTNjsdkk+P8RcLtq1aVvux+qtCjA6xQbDXNcmFsJ+lbXO2CCpRj3XqF P5JevFJOP/AvOF3vwllRyw6W7Cc/z0U= Received: from mail-oo1-f69.google.com (mail-oo1-f69.google.com [209.85.161.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-120-tcz4Ap-8MKup3zisKyCyvg-1; Wed, 24 Apr 2024 17:05:49 -0400 X-MC-Unique: tcz4Ap-8MKup3zisKyCyvg-1 Received: by mail-oo1-f69.google.com with SMTP id 006d021491bc7-5af42673cb1so311759eaf.0 for ; Wed, 24 Apr 2024 14:05:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713992747; x=1714597547; 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=FKdpxzHSUUKZoH7hNmIvnXufi5/OyDFTauZAwJe43tg=; b=PaSqE37cJWDFXBS7kyleo0ClS2EIgNcNSGLYGQOEOpthVf2FDP8uzwb+Xn789LfDN7 JZnFce+MBrdrGdbdyPp2d+PS2CkXXEpOjB3E/S6S79TwnA73bWpn0rHasgd9mR52MWCm oy10yrM/1C5Py/vNy9Qbf8FSdCpyW27PnhHM4VCS72BGjvyt50loqgHsvxXecuh9IrGL /vDUHCgMmniUCBsyWIwbZqQ2Bn4KWmpQqzevQlW7HKvIe/XKvA7y3uNlDnhuIm7At+KE f5TzxpRrYN3zZHfFoOFHSncCGKriaPdlkucbBeXGSWHGZumDfd4mGXN94IXoKWqlclbP nL1g== X-Forwarded-Encrypted: i=1; AJvYcCUg6eMirnfZ41DDevCxXJX86r2L0jN5YQuybC0YNjHEvabhlv1NhDHWj9ZcqJJuIq7zpz3HhCwitJEEvk8CyucqxrA3Kcn8Fw== X-Gm-Message-State: AOJu0YyrdJ+kysCQKRuUwPK9okpv5rBBbfZ7PiSE3bRg7i9iXN6U7Hff xp7S59QQpjM+e19MfySZOK+D7e2wh3+Crytb20J91WX9hgJgOqtTCs7KNWjfAxvWAuEuWP+aXbP q98JViB0TiRwgz2eODSdHvdxcmAbQnHTu5OtnAAd+gD2sWAQ/fScxst0= X-Received: by 2002:a05:6358:b5d3:b0:17e:6a5b:4d3a with SMTP id wb19-20020a056358b5d300b0017e6a5b4d3amr4384295rwc.8.1713992747235; Wed, 24 Apr 2024 14:05:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwZ1Atz9h1eURK+Vnk97b9FVoRFxtbXJHylYvAX6WqHAtk+0E5O9GHF62zRBGEzTLYFjlamg== X-Received: by 2002:a05:6358:b5d3:b0:17e:6a5b:4d3a with SMTP id wb19-20020a056358b5d300b0017e6a5b4d3amr4384254rwc.8.1713992746812; Wed, 24 Apr 2024 14:05:46 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id t1-20020a0cde01000000b0069b4f48003bsm6303461qvk.100.2024.04.24.14.05.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 14:05:46 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Wed, 24 Apr 2024 17:05:45 -0400 (EDT) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org, dmalcolm@redhat.com Subject: Re: [PATCH] c++: fix source printing for "required from here" message In-Reply-To: <8bcaf757-d1fe-4ea5-8128-77b6fbf465e3@redhat.com> Message-ID: <5930feb9-9460-457f-70c4-09c2c662d79e@idea> References: <20240424202206.173103-1-ppalka@redhat.com> <8bcaf757-d1fe-4ea5-8128-77b6fbf465e3@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="8323329-582054307-1713992746=:3760645" X-Spam-Status: No, score=-14.0 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-582054307-1713992746=:3760645 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT On Wed, 24 Apr 2024, Jason Merrill wrote: > 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? > > > > -- >8 -- > > > > 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. > > > > This patch naively fixes this by clearing the prefix before calling > > diagnostic_show_locus. > > > > Before this patch, for error60a.C below we'd print > > > > gcc/testsuite/g++.dg/template/error60a.C: In function ‘void usage()’: > > gcc/testsuite/g++.dg/template/error60a.C:24:3: error: ‘unrelated_error’ was > > not declared in this scope > > 24 | unrelated_error; // { dg-error "not declared" } > > | ^~~~~~~~~~~~~~~ > > gcc/testsuite/g++.dg/template/error60a.C: In instantiation of ‘void > > test(Foo) [with Foo = int]’: > > gcc/testsuite/g++.dg/template/error60a.C:25:13: required from here > > gcc/testsuite/g++.dg/template/error60a.C:24:3: error: 25 | test > > (42); // { dg-message " required from here" } > > gcc/testsuite/g++.dg/template/error60a.C:24:3: error: | > > ~~~~~~~~~~^~~~ > > gcc/testsuite/g++.dg/template/error60a.C:19:24: error: invalid conversion > > from ‘int’ to ‘int*’ [-fpermissive] > > 19 | my_pointer ptr (val); // { dg-error "invalid conversion from > > 'int' to 'int\\*'" } > > | ^~~ > > | | > > | int > > gcc/testsuite/g++.dg/template/error60a.C:9:20: note: initializing argument > > 1 of ‘my_pointer::my_pointer(Foo*) [with Foo = int]’ > > 9 | my_pointer (Foo *ptr) // { dg-message " initializing argument 1" > > } > > | ~~~~~^~~ > > > > and afterward we print > > > > gcc/testsuite/g++.dg/template/error60a.C: In function ‘void usage()’: > > gcc/testsuite/g++.dg/template/error60a.C:24:3: error: ‘unrelated_error’ was > > not declared in this scope > > 24 | unrelated_error; // { dg-error "not declared" } > > | ^~~~~~~~~~~~~~~ > > gcc/testsuite/g++.dg/template/error60a.C: In instantiation of ‘void > > test(Foo) [with Foo = int]’: > > gcc/testsuite/g++.dg/template/error60a.C:25:13: required from here > > 25 | test (42); // { dg-message " required from here" } > > | ~~~~~~~~~~^~~~ > > gcc/testsuite/g++.dg/template/error60a.C:19:24: error: invalid conversion > > from ‘int’ to ‘int*’ [-fpermissive] > > 19 | my_pointer ptr (val); // { dg-error "invalid conversion from > > 'int' to 'int\\*'" } > > | ^~~ > > | | > > | int > > gcc/testsuite/g++.dg/template/error60a.C:9:20: note: initializing argument > > 1 of ‘my_pointer::my_pointer(Foo*) [with Foo = int]’ > > 9 | my_pointer (Foo *ptr) // { dg-message " initializing argument 1" > > } > > | ~~~~~^~~ > > > > gcc/cp/ChangeLog: > > > > * error.cc (print_instantiation_partial_context_line): Clear > > context->printer->prefix around the call to diagnostic_show_locus. > > > > gcc/testsuite/ChangeLog: > > > > * g++.dg/concepts/diagnostic2.C: Expect source line printed > > for the required from here message. > > * g++.dg/template/error60a.C: New test. > > --- > > gcc/cp/error.cc | 2 + > > gcc/testsuite/g++.dg/concepts/diagnostic2.C | 6 ++- > > gcc/testsuite/g++.dg/template/error60a.C | 46 +++++++++++++++++++++ > > 3 files changed, 53 insertions(+), 1 deletion(-) > > create mode 100644 gcc/testsuite/g++.dg/template/error60a.C > > > > 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, > > : _("required from here\n")); > > } > > gcc_rich_location rich_loc (loc); > > + char *saved_prefix = pp_take_prefix (context->printer); > > diagnostic_show_locus (context, &rich_loc, DK_NOTE); > > + context->printer->prefix = saved_prefix; > > I would follow the pattern of c_diagnostic_finalizer here, i.e. using > pp_set_prefix for the restore. 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. > > 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_. If it isn't redundant, then it > should be, i.e. pp_take_prefix should call it instead of directly setting > NULL. > > Some _take_ callers do set(NULL) and others don't; they should definitely be > consistent one way or the other. > > David, what do you think? > > Jason > > --8323329-582054307-1713992746=:3760645--