On 9 Jan 2025, at 20:00, Marek Polacek wrote:

> On Thu, Jan 09, 2025 at 12:05:43PM -0500, Patrick Palka wrote:
>> On Wed, 8 Jan 2025, Jason Merrill wrote:
>>
>>> On 12/21/24 11:35 AM, Simon Martin wrote:
>>>> When erroring out due to an incomplete type, we add a contextual 
>>>> note
>>>> about the type. However, when the error is suppressed by
>>>> -Wno-template-body, the note remains, making the compiler output 
>>>> quite
>>>> puzzling.
>>>>
>>>> This patch makes sure the note is suppressed if we're processing a
>>>> template declaration body with -Wno-template-body.
>>>>
>>>> Successfully tested on x86_64-pc-linux-gnu.
>>>>
>>>>    PR c++/118163
>>>>
>>>> gcc/cp/ChangeLog:
>>>>
>>>>    * cp-tree.h (get_current_template): Declare.
>>>>    * error.cc (get_current_template): Make non static.
>>>>    * typeck2.cc (cxx_incomplete_type_inform): Suppress note when
>>>>    parsing a template declaration with -Wno-template-body.
>>>
>>> I think rather than adding this sort of thing in lots of places 
>>> where an error
>>> is followed by an inform, we should change error to return bool like 
>>> other
>>> diagnostic functions, and check its return value before calling
>>> cxx_incomplete_type_inform or plain inform.  This likely involves 
>>> the same
>>> number of changes, but they should be smaller.
>>>
>>> Patrick, what do you think?
>>
>> That makes sense to me, it's consistent with the 'warning' API and 
>> how
>> we handle issuing a warning followed by a note.  But since the
>> -Wtemplate-body mechanism is really only useful for compiling legacy
>> code where you don't really care about any diagnostics anyway, and
>> the intended way to use it is -fpermissive / -Wno-error=template-body
>> rather than -Wno-template-body, I'd prefer a less invasive solution 
>> that
>> doesn't change the API of 'error' if possible.
>>
>> I wonder if we can work around this by taking advantage of the fact 
>> that
>> notes that follow an error are expected to be linked via an active
>> auto_diagnostic_group?  Roughly, if we issued a -Wtemplate-body
>> diagnostic from an active auto_diagnostic_group then all other
>> diagnostics from that auto_diagnostic_group should also be associated
>> with -Wtemplate-body, including notes.  That way -Wno-template-body 
>> will
>> effectively suppress subsequent notes followed by an eligible error, 
>> and
>> no 'error' callers need to be changed (unless to use
>> auto_diagnostic_group).
>
> FWIW, I love this auto_diagnostic_group idea.
Thanks folks, I’ll explore the auto_diagnostic_group idea (and maybe 
*also* the error returning bool one because I am not a fan of functions 
that “lie” to their callers :-))

I’ll send a follow-up patch in the coming days.

Simon

Reply via email to