On Wed, Jan 21, 2026 at 08:10:05PM +0800, Jason Merrill wrote:
> > Alternatively, we could prevent all such warnings by changing the
> > definition of tem to "tree tem = cp_build_compound_expr (op0, idx,
> > tf_none)". That's probably the better solution but we'd need to check
> > if that would introduce false negatives.
> >
> > Alternatively, we could set "side_effects_flag" for SAVE_EXPR, which
> > would also prevent this warning, but that feels wrong.
>
> Other places in the compiler use warning_sentinel to temporarily disable a
> particular warning; instead of suppress_warning we could here use
>
> warning_sentinel w(warn_unused_value);
Both do very different thing. warning_sentinel temporarily disables
all certain warnings for the duration of the override, whether just for the
exact tree it is making or any other.
suppress_warning arranges that the particular warning will be never
diagnosed for the particular tree, but will be for others.
So, the question is, is the -Wunused-warning diagnosed during those
two build_compound_expr calls? If so, warning_sentinel might be
appropriate.
If it is diagnosed later, then suppress_warning is the way to go.
> > + const bool cond = argc == 10;
> > + (void)(cond ? "" : "")[index()];
> > + (void)(cond ? "" : "")[index_with_side_effect()];
Not really sure I understand the distinction here between index and
index_with_side_effects, from the FE POV, both have side-effects.
There is an optimization pass that determines const/pure attributes
from the bodies of definition, but that is far later than in the FE.
You'd need to use [[gnu::const]] or [[gnu::pure]] attribute on index
to make it something without TREE_SIDE_EFFECTS.
Jakub