This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug build/23087] New: Stop relying on -Wno-narrowing


https://sourceware.org/bugzilla/show_bug.cgi?id=23087

            Bug ID: 23087
           Summary: Stop relying on -Wno-narrowing
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: build
          Assignee: unassigned at sourceware dot org
          Reporter: palves at redhat dot com
  Target Milestone: ---

Early in gdb's C++ conversion, at
<https://sourceware.org/ml/gdb-patches/2015-02/msg00203.html>, we added
-Wno-narrowing to the build flags with the following comment:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
. Adding -Wno-narrowing suppresses thousands of instances of this warning:

  gdb/arm-linux-tdep.c:439:1: error: narrowing conversion of â-1â from int to
âULONGEST {aka long unsigned int} inside { } is ill-formed in C++11
[-Werror=narrowing]
  gdb/arm-linux-tdep.c:439:1: error: narrowing conversion of -1 from LONGEST
{aka long int} to ULONGEST {aka long unsigned int} inside { } is ill-formed in
C++11 [-Werror=narrowing]
  gdb/arm-linux-tdep.c:450:1: error: narrowing conversion of -1 from int to
ULONGEST {aka long unsigned int} inside { } is ill-formed in C++11
[-Werror=narrowing]

We can defer handling those until we target C++11.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Not that long after however, we started requiring C++11, but the warning/error
suppression is still in place, as the reason for having it.

I don't think any compiler is going to miscompile such code, though ideally
we'd fix it for good, since the narrowing conversions are ill-formed C++11.

We could fix that with e.g., explicit casting at each call site:

 CORE_ADDR breaks[2] = { (CORE_ADDR) -1, (CORE_ADDR) -1 };

Or perhaps better add a CORE_ADDR_MAX and use it throughout:

 #define CORE_ADDR_MAX ((CORE_ADDR) -1)

 CORE_ADDR breaks[2] = { CORE_ADDR_MAX, CORE_ADDR_MAX };

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]