https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118392
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Simon Martin <simar...@gcc.gnu.org>: https://gcc.gnu.org/g:0f1d55a75b09c13e3db09654c2b5aaad5741262f commit r16-383-g0f1d55a75b09c13e3db09654c2b5aaad5741262f Author: Simon Martin <si...@nasilyan.com> Date: Mon May 5 10:12:08 2025 +0200 c++: Inhibit subsequent warnings/notes in diagnostic_groups with an inhibited warning [PR118163,PR118392] Those 2 PRs show that even when using a *single* diagnostic_group, it's possible to end up with a warning being inhibited and its associated note still emitted, which leads to puzzling user experience. Example from PR118392: === $ gcc/cc1plus inhibit-warn-3.C -w inhibit-warn-3.C:10:17: note: only here as a âfriendâ 10 | friend void bar(); | ^~~ === Following a suggestion from ppalka@, this patch keeps track of the "diagnostic depth" at which a warning in inhibited, and makes sure that all subsequent notes at that depth or deeper are inhibited as well, until a subsequent warning or error is accepted at that depth, or the diagnostic_group or nesting level is popped. PR c++/118163 PR c++/118392 gcc/ChangeLog: * diagnostic.cc (diagnostic_context::initialize): Initialize m_diagnostic_groups.m_inhibiting_notes_from. (diagnostic_context::inhibit_notes_in_group): New. (diagnostic_context::notes_inhibited_in_group): New (diagnostic_context::report_diagnostic): Call inhibit_notes_in_group and notes_inhibited_in_group. (diagnostic_context::end_group): Call inhibit_notes_in_group. (diagnostic_context::pop_nesting_level): Ditto. * diagnostic.h (diagnostic_context::m_diagnostic_groups): Add member to track the depth at which a warning has been inhibited. (diagnostic_context::notes_inhibited_in_group): Declare. (diagnostic_context::inhibit_notes_in_group): Declare. * doc/ux.texi: Document diagnostic_group behavior with regards to inhibited warnings. gcc/testsuite/ChangeLog: * g++.dg/diagnostic/incomplete-type-2.C: New test. * g++.dg/diagnostic/incomplete-type-2a.C: New test. * g++.dg/diagnostic/inhibit-warn-3.C: New test.