]> git.ipfire.org Git - thirdparty/gcc.git/commit - libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc
c++: Don't hide narrowing errors in system headers
authorMarek Polacek <polacek@redhat.com>
Thu, 15 Jul 2021 22:45:49 +0000 (18:45 -0400)
committerMarek Polacek <polacek@redhat.com>
Fri, 16 Jul 2021 13:28:37 +0000 (09:28 -0400)
commite32234536f361796e7cad8ed69a1c0bb46ee55de
treec0ac3663d3c024c8c2cb55f07e8a476a557d32e0
parent650c70a9fe7198394d3bbe4c0b1a7a73dc0bdd4a
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.
gcc/cp/typeck2.c
gcc/testsuite/g++.dg/cpp1y/Wnarrowing2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/Wnarrowing2.h [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc