diff options
author | Marek Polacek <polacek@redhat.com> | 2021-07-15 18:45:49 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2021-07-16 09:28:37 -0400 |
commit | e32234536f361796e7cad8ed69a1c0bb46ee55de (patch) | |
tree | c0ac3663d3c024c8c2cb55f07e8a476a557d32e0 /gcc/cp/typeck2.c | |
parent | 650c70a9fe7198394d3bbe4c0b1a7a73dc0bdd4a (diff) | |
download | gcc-e32234536f361796e7cad8ed69a1c0bb46ee55de.zip gcc-e32234536f361796e7cad8ed69a1c0bb46ee55de.tar.gz gcc-e32234536f361796e7cad8ed69a1c0bb46ee55de.tar.bz2 |
c++: Don't hide narrowing errors in system headers
Jonathan pointed me at this issue where
constexpr unsigned f() { constexpr int n = -1; return unsigned{n}; }
is accepted in system headers, despite the narrowing conversion from
a constant. I suspect that whereas narrowing warnings should be
disabled, ill-formed narrowing of constants should be a hard error
(which can still be disabled by -Wno-narrowing).
gcc/cp/ChangeLog:
* typeck2.c (check_narrowing): Don't suppress the pedantic error
in system headers.
libstdc++-v3/ChangeLog:
* testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Add
dg-error.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/Wnarrowing2.C: New test.
* g++.dg/cpp1y/Wnarrowing2.h: New test.
Diffstat (limited to 'gcc/cp/typeck2.c')
-rw-r--r-- | gcc/cp/typeck2.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 6679e24..dcfdff2 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -986,6 +986,7 @@ check_narrowing (tree type, tree init, tsubst_flags_t complain, { int savederrorcount = errorcount; global_dc->pedantic_errors = 1; + auto s = make_temp_override (global_dc->dc_warn_system_headers, true); pedwarn (loc, OPT_Wnarrowing, "narrowing conversion of %qE from %qH to %qI", init, ftype, type); |