diagnostic: add permerror variants with opt
commitef10cb8683ae60c161eb88df381e02f95f6e3e30
authorJason Merrill <jason@redhat.com>
Tue, 16 May 2023 21:02:51 +0000 (16 17:02 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 18 Oct 2023 14:00:25 +0000 (18 10:00 -0400)
treee9cdb75ddb8e2b4268a88b0ed492a95a3936c3c8
parentaf4bb221153359f5948da917d5ef2df738bb1e61
diagnostic: add permerror variants with opt

In the discussion of promoting some pedwarns to be errors by default, rather
than move them all into -fpermissive it seems to me to make sense to support
DK_PERMERROR with an option flag.  This way will also work with
-fpermissive, but users can also still use -Wno-error=narrowing to downgrade
that specific diagnostic rather than everything affected by -fpermissive.

So, for diagnostics that we want to make errors by default we can just
change the pedwarn call to permerror.

The tests check desired behavior for such a permerror in a system header
with various flags.  The patch preserves the existing permerror behavior of
ignoring -w and system headers by default, but respecting them when
downgraded to a warning by -fpermissive.

This seems similar to but a bit better than the approach of forcing
-pedantic-errors that I previously used for -Wnarrowing: specifically, in
that now -w by itself is not enough to silence the -Wnarrowing
error (integer-pack2.C).

gcc/ChangeLog:

* doc/invoke.texi: Move -fpermissive to Warning Options.
* diagnostic.cc (update_effective_level_from_pragmas): Remove
redundant system header check.
(diagnostic_report_diagnostic): Move down syshdr/-w check.
(diagnostic_impl): Handle DK_PERMERROR with an option number.
(permerror): Add new overloads.
* diagnostic-core.h (permerror): Declare them.

gcc/cp/ChangeLog:

* typeck2.cc (check_narrowing): Use permerror.

gcc/testsuite/ChangeLog:

* g++.dg/ext/integer-pack2.C: Add -fpermissive.
* g++.dg/diagnostic/sys-narrow.h: New test.
* g++.dg/diagnostic/sys-narrow1.C: New test.
* g++.dg/diagnostic/sys-narrow1a.C: New test.
* g++.dg/diagnostic/sys-narrow1b.C: New test.
* g++.dg/diagnostic/sys-narrow1c.C: New test.
* g++.dg/diagnostic/sys-narrow1d.C: New test.
* g++.dg/diagnostic/sys-narrow1e.C: New test.
* g++.dg/diagnostic/sys-narrow1f.C: New test.
* g++.dg/diagnostic/sys-narrow1g.C: New test.
* g++.dg/diagnostic/sys-narrow1h.C: New test.
* g++.dg/diagnostic/sys-narrow1i.C: New test.
16 files changed:
gcc/cp/typeck2.cc
gcc/diagnostic-core.h
gcc/diagnostic.cc
gcc/doc/invoke.texi
gcc/testsuite/g++.dg/diagnostic/sys-narrow.h [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/sys-narrow1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/sys-narrow1a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/sys-narrow1b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/sys-narrow1c.C [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/sys-narrow1d.C [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/sys-narrow1e.C [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/sys-narrow1f.C [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/sys-narrow1g.C [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/sys-narrow1h.C [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/sys-narrow1i.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/integer-pack2.C