Skip to content

Commit

Permalink
build: Add -Wsign-conversion to CXXFLAGS
Browse files Browse the repository at this point in the history
-Wsign-conversion is by default enabled in Clang with -Wconversion,
but disabled in GCC. Unintented type coercion can misinterpret the
sign as in:

    libdnf5-cli/output/transaction_table.cpp:181:97: error: conversion to ‘long unsigned int’ from ‘int’ may change the sign of the result [-Werror=sign-conversion]
      181 |        P_(" Skipping:        {:4} package\n", " Skipping:        {:4} packages\n", skips), skips)
          |                                                                                    ^~~~~

This would be missed when compiling with GCC, but causing a build
failure with Clang.

This patch brings GCC and Clang compilers in line, both to enable
-Wsign-conversion. However, it disables the warning for SWIG-generated
bindings as the generated code violates the warning many times, like
here for Perl:

    bindings/perl5/libdnf5/CMakeFiles/perl5_advisory.dir/advisoryPERL_wrap.cxx:700:36: error: conversion to ‘long unsigned int’ from ‘long int’ may change the sign of the result [-Werror=sign-conversion]
      700 |   if (strlen(name) + 1 > (bsz - (r - buff))) return 0;
          |                                 ~~~^~~~~~~

Related: rpm-software-management#1701
  • Loading branch information
ppisar committed Sep 17, 2024
1 parent 1361f69 commit a6d9b7f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ add_compile_options("-fmacro-prefix-map=${PROJECT_SOURCE_DIR}/=")

# warnings
add_compile_options(-Wall -Wextra -Werror)
add_compile_options(-Wcast-align -Wformat-nonliteral -Wmissing-format-attribute -Wredundant-decls -Wsign-compare -Wtype-limits -Wuninitialized -Wwrite-strings)
add_compile_options(-Wcast-align -Wformat-nonliteral -Wmissing-format-attribute -Wredundant-decls -Wsign-compare -Wsign-conversion -Wtype-limits -Wuninitialized -Wwrite-strings)
add_compile_options(-Werror=unused-result -Wodr)

# not sure about the conversion warnings being errors; review later
Expand Down
1 change: 1 addition & 0 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(SWIG_COMPILE_OPTIONS
-Wno-missing-declarations
-Wno-missing-field-initializers
-Wno-sign-compare
-Wno-sign-conversion
-Wno-sometimes-uninitialized
-Wno-strict-aliasing
-Wno-unused-function
Expand Down

0 comments on commit a6d9b7f

Please sign in to comment.