From 76fef263e851ca1682e019a37a9864b57d414ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Tue, 17 Sep 2024 12:58:50 +0200 Subject: [PATCH] build: Add -Wsign-conversion to CXXFLAGS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -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: https://github.com/rpm-software-management/dnf5/pull/1701 --- CMakeLists.txt | 2 +- bindings/CMakeLists.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1621a8384..5cd3931fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/bindings/CMakeLists.txt b/bindings/CMakeLists.txt index d97ad2405..8593e8bcd 100644 --- a/bindings/CMakeLists.txt +++ b/bindings/CMakeLists.txt @@ -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