Proposal: Warnings for unnecessary warning suppression
Archie Cobbs
archie.cobbs at gmail.com
Thu Mar 6 16:12:50 UTC 2025
On Thu, Mar 6, 2025 at 9:45 AM Magnus Ihse Bursie <
magnus.ihse.bursie at oracle.com> wrote:
> But having warning suppression that does not make sense for a given
> compiler is not necessary a problem, and if it should be flagged, it
> should be something you opt into, and possibly, as Joe suggests, somehow
> lie outside normal warnings.
I did think about this question of interactions between -Werror, -Xlint:all,
and different compiler versions with respect to these new warning
categories. In particular, thinking through the scenarios is why the
-Xlint:suppression flag is ignored unless the -Xlint:options flag is also
enabled (see below).
Here are my thoughts... please check my logic:
- In the case of @SuppressWarnings annotations:
- What if a compiler doesn't recognize
@SuppressWarnings("suppression")?
- No problem - it's already the case that unrecognized keys are
ignored
- What if two compiler versions handle some warning "foo"
differently, so that one warns where one doesn't?
- In this case @SuppressWarnings("foo") will be unnecessary in one
case but not the other
- In the latter you'd then get a "suppression" warning if
enabled and the compiler supports it
- But this happens all the time - i.e., a new warning is
introduced or an existing warning's behavior changes
- The usual answer is to add @SuppressWarnings("foo") to suppress
the warning in the compiler version where it occurs
- Similarly, the answer here is to add
@SuppressWarnings("suppression") to suppress the warning in the
compiler version where it occurs
- In the case of -Xlint:suppression-option flags:
- It's always safe to add -Xlint:-suppression-option to a build to
restore the current behavior IF every compiler version knows that flag
- If some compiler version doesn't know -Xlint:-suppression-option
then -Xlint:-options also works
- So there's always a way to disable suppression warnings, regardless
of whether the compiler knows about "suppression-option"
- Using -Xlint:-options is only a temporary measure until all
compiler versions support "suppression-option
-Archie
--
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20250306/09ab4573/attachment-0001.htm>
More information about the compiler-dev
mailing list