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 6541E3846426 for ; Wed, 24 Apr 2024 20:54:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6541E3846426 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 6541E3846426 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=1713992087; cv=none; b=phcdh05k1w5/JbjiSZVh75rqxtgMkfIMfb/2jsNL25UeuwKqmiEcx5zt+u3lyPXU3zFPg3RfPCMcjhu8W8C4aIQeOD3T/u0iy8iSMr2q8LFNtQqI4o8e9jyT3/2evx8VMAw625m8ALZY066SHS1TvNttHfQnrRbVQUbbtUEMOkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713992087; c=relaxed/simple; bh=eprDGKCMS7izIdRr5jyejN/bz1Zc0xLmxDMczwiqZys=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=T83+ehG046PXi1jSna99e8w3Q+4+S9ddtDbWB6qGs7wQZImqPMhHSvEALBnusEyW4qBRdNSrhIH2kDdqq4QWAJd355LLyL/ZA15XJ81P/UgTuRFm2a/pVJLXQomceOjFZTI6quKilcD9b5ZjLv9nHFbcftyaBqSxjZHSQPByyRQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713992085; 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=SRTlvRgCRZ9gWJpTDzdUBFOkGDCLV6ecI9LMNr+ufUc=; b=URYrRBZE0kUs4jQpHdUOIbN9p0FucMWhfVmxcRIbl9aG9C05lw3xdC9UvoXeI/jbOBqjr0 Ww65IRQSO8U8TCYcDQYvP01/B5nFLojAKRLZAmitF3ZhTtGLM04cqvog9x77Izk2fwDVir UwArdtgRtpAksKVHtQiGm70z0stH4QM= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-519-NJ-cjl3bO-yyBrURH83qbA-1; Wed, 24 Apr 2024 16:54:43 -0400 X-MC-Unique: NJ-cjl3bO-yyBrURH83qbA-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7906766e2daso29979985a.0 for ; Wed, 24 Apr 2024 13:54:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713992083; x=1714596883; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SRTlvRgCRZ9gWJpTDzdUBFOkGDCLV6ecI9LMNr+ufUc=; b=osy7/HHk/NgzA4b5p0AKGZDxSoHx/kfHSIrHlcr6QT/RmQ5yCe+INNlFWxuDvFnIiq 8KIwLLBv8KrjHlMCbcmhKEHtH4xX9rqY9Z/7eNbcvly86xwEOn+ejkGlco3+VmwPXLtS C+GN6AZhQTrznDwxrH4B7LpZl5cmfLIQ5qW+wt213WI4XUlbWpdk1o5qV55HiiF3pNHu nAwlzRt0YbfxIAaaDLYF2xb/LXRuSUNUQtY/l5YmaC9igmuGR0V3+DM9o4c6cHfMABt1 1j9IKH1eAgQLP1n8dX7MB26NRmrzy5GxMjFG68MQ5163xpHMOaByoy4DzWwgxJJW3A37 J9xg== X-Forwarded-Encrypted: i=1; AJvYcCXAqSfNJ1TQ53n9TFQzThn9SUS6axxs2M6j8v9fN5Fg4XPTqTBG3ZlZyxr9Adho4xUam68LDBlyj4TZJG31WR3Rs+/IX6NWmA== X-Gm-Message-State: AOJu0Yzn2SZb9DU451ReK0UGGZo01hGt1Ox8W3y3MdaIe/SZm9Rc1cvI MkFmTsVHhaFWnSNjvc0G+1YwX3Vdt/1+feqwn8Tzrox67IATglI0HgoamAOkJIaS9wRNO05H3U2 XoUP1zJzopPFAz89CNhmkdEnk8wQ1oIFJrS82A7RZcgt/pmkxbvJUCN4= X-Received: by 2002:a05:620a:8222:b0:790:6e17:c38f with SMTP id ow34-20020a05620a822200b007906e17c38fmr3827103qkn.48.1713992082742; Wed, 24 Apr 2024 13:54:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkENEfgdOo98vX0jps8ItXRzGXwD78XZEiSLge51GhvznxApTC2SAgLu8Uo3uKJLaD7fqiow== X-Received: by 2002:a05:620a:8222:b0:790:6e17:c38f with SMTP id ow34-20020a05620a822200b007906e17c38fmr3827092qkn.48.1713992082364; Wed, 24 Apr 2024 13:54:42 -0700 (PDT) Received: from [192.168.1.130] (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 b17-20020a05620a089100b0078d5b3b5b4asm6405217qka.125.2024.04.24.13.54.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Apr 2024 13:54:41 -0700 (PDT) Message-ID: <8bcaf757-d1fe-4ea5-8128-77b6fbf465e3@redhat.com> Date: Wed, 24 Apr 2024 16:54:39 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: fix source printing for "required from here" message To: Patrick Palka , gcc-patches@gcc.gnu.org Cc: dmalcolm@redhat.com References: <20240424202206.173103-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20240424202206.173103-1-ppalka@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.6 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 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. 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