arakiken / mlterm

Other
156 stars 13 forks source link

`-Wincompatible-function-pointer-types` warnings (becomes fatal with upcoming Clang 16) #50

Open thesamesam opened 1 year ago

thesamesam commented 1 year ago

Originally reported downstream in Gentoo at https://bugs.gentoo.org/870565 when building 3.9.2.

Clang 16 makes -Wincompatible-function-pointer-types fatal. I had the following errors when building mlterm:

bl_conf.c:146:3: warning: comparison of distinct pointer types ('int (*)(char *, u_int)' (aka 'int (*)(char *, unsigned int)') and 'int (*)(int, u_int)' (aka 'int (*)(int, unsigned int)')) [-Wcompare-distinct-pointer-types]
  bl_map_set(result, conf->conf_entries, key, entry);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./bl_map.h:141:30: note: expanded from macro 'bl_map_set'
        if ((map)->hash_func == bl_map_hash_int || (map)->hash_func == bl_map_hash_int_fast) { \
            ~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~
bl_conf.c:146:3: warning: comparison of distinct pointer types ('int (*)(char *, u_int)' (aka 'int (*)(char *, unsigned int)') and 'int (*)(int, u_int)' (aka 'int (*)(int, unsigned int)')) [-Wcompare-distinct-pointer-types]
  bl_map_set(result, conf->conf_entries, key, entry);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./bl_map.h:141:69: note: expanded from macro 'bl_map_set'
        if ((map)->hash_func == bl_map_hash_int || (map)->hash_func == bl_map_hash_int_fast) { \
                                                   ~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~
bl_conf.c:146:3: error: incompatible function pointer types assigning to 'int (*)(char *, u_int)' (aka 'int (*)(char *, unsigned int)') from 'int (int, u_int)' (aka 'int (int, unsigned int)') [-Wincompatible-function-pointer-types]
  bl_map_set(result, conf->conf_entries, key, entry);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./bl_map.h:143:30: note: expanded from macro 'bl_map_set'
            (map)->hash_func = bl_map_hash_int;                                                \
                             ^ ~~~~~~~~~~~~~~~
bl_conf.c:146:3: error: incompatible function pointer types assigning to 'int (*)(char *, u_int)' (aka 'int (*)(char *, unsigned int)') from 'int (int, u_int)' (aka 'int (int, unsigned int)') [-Wincompatible-function-pointer-types]
  bl_map_set(result, conf->conf_entries, key, entry);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./bl_map.h:146:30: note: expanded from macro 'bl_map_set'
            (map)->hash_func = bl_map_hash_int_fast;                                           \
                             ^ ~~~~~~~~~~~~~~~~~~~~
bl_conf.c:205:3: warning: comparison of distinct pointer types ('int (*)(char *, u_int)' (aka 'int (*)(char *, unsigned int)') and 'int (*)(int, u_int)' (aka 'int (*)(int, unsigned int)')) [-Wcompare-distinct-pointer-types]
  bl_map_new_with_size(char *, bl_conf_entry_t *, conf->conf_entries, bl_map_hash_str,
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./bl_map.h:50:21: note: expanded from macro 'bl_map_new_with_size'
    if (__hash_func == bl_map_hash_int) {                                                \
        ~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~
bl_conf.c:205:3: error: incompatible function pointer types assigning to 'int (*)(char *, u_int)' (aka 'int (*)(char *, unsigned int)') from 'int (int, u_int)' (aka 'int (int, unsigned int)') [-Wincompatible-function-pointer-types]
  bl_map_new_with_size(char *, bl_conf_entry_t *, conf->conf_entries, bl_map_hash_str,
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./bl_map.h:52:26: note: expanded from macro 'bl_map_new_with_size'
        (map)->hash_func = bl_map_hash_int;                                              \
                         ^ ~~~~~~~~~~~~~~~
bl_conf.c:205:3: error: incompatible function pointer types assigning to 'int (*)(char *, u_int)' (aka 'int (*)(char *, unsigned int)') from 'int (int, u_int)' (aka 'int (int, unsigned int)') [-Wincompatible-function-pointer-types]
  bl_map_new_with_size(char *, bl_conf_entry_t *, conf->conf_entries, bl_map_hash_str,
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./bl_map.h:55:26: note: expanded from macro 'bl_map_new_with_size'
        (map)->hash_func = bl_map_hash_int_fast;                                         \
                         ^ ~~~~~~~~~~~~~~~~~~~~
4 warnings and 4 errors generated.

Full build.log at https://bugs.gentoo.org/attachment.cgi?id=806698.

arakiken commented 1 year ago

Thanks. I fixed incompatible function pointer types error. https://github.com/arakiken/mlterm/commit/dbf581cccc8ca59d92c8f84b563d5d2376c11208

thesamesam commented 10 months ago

We seem to still be seeing this in ui_window_cairo.c (https://bugs.gentoo.org/919221):

ui_window_cairo.c:57:12: error: incompatible pointer to integer conversion
      initializing 'u_long' (aka 'unsigned long') with an expression of type
      'void *' [-Wint-conversion]
   57 |     u_long pixel = cairo_get_user_data(cr, (cairo_user_data_key_t*)2);
      |            ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui_window_cairo.c:112:25: warning: cast to 'void *' from smaller integer type
      'int' [-Wint-to-void-pointer-cast]
  112 |                         (void*)((fg_color->red << 16) | (fg_color->green << 8) |
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  113 |                                 (fg_color->blue) | (fg_color->alpha << 24)),
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui_window_cairo.c:205:25: warning: cast to 'void *' from smaller integer type
      'int' [-Wint-to-void-pointer-cast]
  205 |                         (void*)((fg_color->red << 16) | (fg_color->green << 8) |
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  206 |                                 (fg_color->blue) | (fg_color->alpha << 24)),
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

GCC 14 will make this an error by default.

arakiken commented 9 months ago

Thanks. This error has been already fixed. -> https://github.com/arakiken/mlterm/commit/f971955cf54a721e6a53191c3b86fbdab4bfbfd5