Opened 4 years ago

Closed 4 years ago

#12575 closed build error (fixed)

C++0x compilation error: narrowing conversions in xbm files.

Reported by: jan_van_dijk Owned by:
Priority: normal Milestone: 3.0.0
Component: wxGTK Version: stable-latest
Keywords: c+0x narrowing conversion, gdk, bitmap Cc:
Blocked By: Blocking:
Patch: yes

Description

gcc refuses to compile trunk/wxGTK in C++0x mode. The culprit is that in the .xbm files char-arrays are initialised with values >127. This does not fly if char==signed char, e.g:

../src/gtk/bdiag.xbm:6:50: error: narrowing conversion of ‘128’ from ‘int’ to ‘char’ inside { } [-fpermissive]

I admit that the REAL problem is upstream: gdk_bitmap_create_from_data should have expected unsigned char instead of char arguments. This has been noted in 2001, but was apparently never fixed, see for example

http://markmail.org/message/7igyd4n7sw7g6lft

... so this observation is merely of theeoretical interest.

The attached patch reimplements the arrays as unsigned char ones, and uses a reinterpret_cast<const char*> in src/gtk/dcclient.cpp

Yes, this is ugly. If anybody has a better idea, please let me know and I will try to prepare and test an alternative patch. Otherwise, please consider this for inclusion. Thank you in advance.

Regards, Jan van Dijk.

Attachments (1)

xbm.diff download (4.9 KB) - added by jan_van_dijk 4 years ago.
patch against r65839

Download all attachments as: .zip

Change History (5)

Changed 4 years ago by jan_van_dijk

patch against r65839

comment:1 follow-up: Changed 4 years ago by vadz

  • Keywords c+0x added
  • Milestone set to 3.0

This is ugly but worse is that I'm not sure whether any XBM editors are going to be able to open the file after such modification. OTOH the only way to avoid changing the XBMs yet satisfy g++ that I see is to use an even uglier #define char unsigned char hack before including them and I'm not sure if it's worth it, these files are probably not edited that often.

comment:2 in reply to: ↑ 1 Changed 4 years ago by jan_van_dijk

Replying to vadz:

This is ugly but worse is that I'm not sure whether any XBM editors are going to be able to open the file after such modification. OTOH the only way to avoid changing the XBMs yet satisfy g++ that I see is to use an even uglier #define char unsigned char hack before including them and I'm not sure if it's worth it, these files are probably not edited that often.

For what it's worth:

comment:3 Changed 4 years ago by vadz

  • Status changed from new to confirmed

Ok, this definitely looks convincing, thanks for testing! Will apply the patch soon.

comment:4 Changed 4 years ago by VZ

  • Resolution set to fixed
  • Status changed from confirmed to closed

(In [65846]) Use unsigned char for XBM bitmaps data.

This fixes compilation with g++ in C++0x mode in which conversions of
constants not fitting into signed char range to char are not permitted.

Closes #12575.

Note: See TracTickets for help on using tickets.