On Tue, 20 Jan 2026 at 09:36, Jakub Jelinek <[email protected]> wrote:
>
> On Tue, Jan 20, 2026 at 10:14:35AM +0100, Jakub Jelinek wrote:
> > On Mon, Jan 19, 2026 at 03:57:08PM +0100, Josef Melcr wrote:
> > > +<!-- introduced in 0eac9cfee8cb0b21de866a04d5d59685ab35208f -->
> > > +
> > > +<p>
> > > +Since GCC 16, <code>-Wunused-but-set-*</code> warning options no longer
> > > +consider preincrements and postincrements as uses, which may lead to
> > > +compilation failures when using <code>-Werror</code>.
> > > +</p>
> >
> > That IMHO doesn't describe the change correctly (the change wasn't by
> > -Wall/-W default only about pre/post increments but also about var @= expr)
> > and more importantly, doesn't tell users what they should do.
> >
> > The PR44677 change simply changed the -Wunused-but-set-* warnings to
> > have multiple levels and the old options as well as defaults implied
> > by -Wall or -W default to the =3 level, while the GCC 15 and earlier
> > provided level was equivalent to the =1 level.
> > Usually porting_to.html shows some code snippet, describes what changed
> > and suggests what to do.
> > I think this porting_to.html entry should refer to
> > https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wunused-but-set-variable_003d
> > and maybe https://gcc.gnu.org/PR44677 , show the code example
> > mentioned in the documentation and suggest users that they can either
> > remove the unused but set variables/parameters to fix the warnings,
> > or make them used e.g. through (void) casts, or if some project generally
> > likes the previous behavior, lower the level to -Wunused-but-set-variable=1
> > or similar.
>
> Here is my attempt to do that.
>
> Ok for wwwdocs?
>
> diff --git a/htdocs/gcc-16/porting_to.html b/htdocs/gcc-16/porting_to.html
> index 3bd1ff2b..783ec821 100644
> --- a/htdocs/gcc-16/porting_to.html
> +++ b/htdocs/gcc-16/porting_to.html
> @@ -31,9 +31,49 @@ and provide solutions. Let us know if you have suggestions 
> for improvements!
>  <!-- introduced in 0eac9cfee8cb0b21de866a04d5d59685ab35208f -->
>
>  <p>
> -Since GCC 16, <code>-Wunused-but-set-*</code> warning options no longer
> -consider preincrements and postincrements as uses, which may lead to
> -compilation failures when using <code>-Werror</code>.
> +Since GCC 16, <code>-Wunused-but-set-*</code> warning options have been
> +extended to have multiple levels of what kind of uses of otherwise

I found this a bit hard to parse. Maybe:

"multiple levels controlling what kinds of uses disable the warnings
for variables which are otherwise unused."

This is a bit longer, but I think clearer.

> +unused variables disable the warnings.  Older versions of GCC only
> +implemented what has become <code>-Wunused-but-set-variable=1</code>
> +or <code>-Wunused-but-set-parameter=1</code>, while the new default
> +for <code>-Wunused-but-set-variable</code> or
> +<code>-Wunused-but-set-parameter</code> is <code>=3</code> (also defaulted
> +for <code>-Wall</code> resp. <code>-Wextra</code>.

Missing closing paren?

I'm not sure what "-Wall resp. -Wextra" means here. I checked the
manual and found that the "variable" form is enabled by -Wall and the
"parameter" form by -Wextra, but without going and looking that up I
found this sentence confusing.

Maybe:

"(the new defaults are also used when these warnings are enabled by
-Wall or -Wextra, respectively)."


> +<code>=2</code> ignores pre/post inc/decrements on the variable,
> +<code>=3</code> also compound assignments if the lhs variable is not used
> +on the rhs as well.

Maybe:

"=3 also ignores compound assignments if the LHS variable is not also
used on the RHS."

> +<pre><code>
> +void foo (void) {
> +  int a = 1; // -Wunused-variable warning
> +  int b = 0; // Warning for -Wunused-but-set-variable=<i>n</i> <i>n</i> 
> &gt;= 1
> +  b = 1; b = 2;
> +  int c = 0; // Warning for -Wunused-but-set-variable=<i>n</i> <i>n</i> 
> &gt;= 2
> +  ++c; c--; --c; c++;
> +  int d = 0; // Warning for -Wunused-but-set-variable=<i>n</i> <i>n</i> 
> &gt;= 3
> +  d += 4;
> +  int e = 0; // No warning, cast to void
> +  (void) e;
> +  int f = 0; // No warning, f used
> +  int g = f = 5;
> +  (void) g;
> +  int h = 0; // No warning, preincrement used
> +  int i = ++h;
> +  (void) i;
> +  int j = 0; // No warning, postdecrement used
> +  int k = j--;
> +  (void) k;
> +  int l = 0; // No warning, l used
> +  int m = l |= 2;
> +  (void) m;
> +}
> +</code></pre>
> +In order to avoid the warnings, one can either remove newly diagnosed
> +variables or parameters which aren't used except in pre/post inc/decrements
> +or compound assignments, make them used in some way
> +including just casting to <code>(void)</code> or lowering the level

Maybe:

"make them used in some way, e.g. just casting to (void), or lowering ..."

i.e. turn the "including just casting" to e.g. and put commas before
and after that clause.

> +of the warning.  See
> +<a 
> href=https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wunused-but-set-variable_003d";
> +<code>-Wunused-but-set-*</code></a> documentation for more details.
>  </p>
>
>  </body>
>
>
>         Jakub
>

Reply via email to