[Bug c++/108363] New: Narrowing conversion errors are suppressed with the -w flag

novulae at hotmail dot com gcc-bugzilla@gcc.gnu.org
Tue Jan 10 19:49:24 GMT 2023


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108363

            Bug ID: 108363
           Summary: Narrowing conversion errors are suppressed with the -w
                    flag
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: novulae at hotmail dot com
  Target Milestone: ---

I ran across this with GCC 12.2.0, but have confirmed that it still reproduces
with trunk via Godbolt.

With the below test case, a narrowing error is expected, and is indeed offered
by GCC. However, when warnings are suppressed, the error is suppressed as well.

$ cat test.cpp
template<bool> struct X {
  using m = int;
};

template<typename>
using Y = X< sizeof(int) >::m;

$ g++ -c -w -std=c++20 test.cpp

$ g++ -c -std=c++20 test.cpp
test.cpp:6:26: error: narrowing conversion of ‘4’ from ‘long unsigned int’ to
‘bool’ [-Wnarrowing]
    6 | using Y = X< sizeof(int) >::m;
      |                          ^

Clang issues a corresponding error both with and without -w.


More information about the Gcc-bugs mailing list