-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
maint: Enable -Werror
compiler flag for GCC, Clang and AppleClang
#3611
Changes from 3 commits
297600d
1139c2b
b8ca583
f31b567
13a1aaf
e072216
c663393
4fb6ee9
9c5d213
85354bc
d62357e
f69c782
f7c4977
37959d8
fda8aae
13accfa
0faf603
12d8c9f
a0a8cea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,6 +264,22 @@ set( | |
${LIBMAMBA_SOURCE_DIR}/api/shell.cpp | ||
${LIBMAMBA_SOURCE_DIR}/api/update.cpp | ||
) | ||
# TODO: remove when switch to C++20 | ||
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") | ||
# This file uses capturing structured bindings, which was fixed in C++20 | ||
set_source_files_properties( | ||
${LIBMAMBA_SOURCE_DIR}/download/mirror_impl.cpp | ||
PROPERTIES COMPILE_FLAGS -Wno-c++20-extensions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is nothing wrong with our code and nothing to change there. So we can safely ignore the warning we're using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically, this construction is C++20, not C++17. It works with gcc and msvc though, and the warning is still here with Clang, even if we pass the C++20 option (that's a known bug), so I agree that we can ignore it. |
||
) | ||
endif() | ||
|
||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
# GCC reports dangling reference when using std::invoke with data members | ||
set_source_files_properties( | ||
${LIBMAMBA_SOURCE_DIR}/solver/problems_graph.cpp | ||
PROPERTIES COMPILE_FLAGS -Wno-error=dangling-reference | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be useful warning/error, so I'm turning it back to being warning for this file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any way to make that change as part of the source code instead of here (like disabling warnings)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, fortunately it happens in functions located near each other, so we can only write pragmas once. |
||
) | ||
endif() | ||
|
||
foreach(script ${SHELL_SCRIPTS}) | ||
list(APPEND LIBMAMBA_SOURCES shell_scripts/${script}.cpp) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,10 +93,17 @@ namespace solv | |
|
||
namespace | ||
{ | ||
// This function is only used in `assert()` expressions | ||
// That's why it might get reported as unused in Release builds | ||
#pragma GCC diagnostic push | ||
#pragma GCC diagnostic ignored "-Wunused-function" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I explained above why this happens. |
||
|
||
auto is_reldep(::Id id) -> bool | ||
{ | ||
return ISRELDEP(static_cast<std::make_unsigned_t<::Id>>(id)) != 0; | ||
} | ||
|
||
#pragma GCC diagnostic pop | ||
} | ||
|
||
auto ObjPoolView::get_string(StringId id) const -> std::string_view | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,9 +31,7 @@ namespace mamba::util | |
} | ||
else | ||
{ | ||
using int_t = Int; | ||
return static_cast<int_t>(condition) * true_val | ||
+ (int_t(1) - static_cast<int_t>(condition)) * false_val; | ||
return condition ? true_val : false_val; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is significantly easier to read and doesn't deal with arithmetics at all (which was giving warnings in some cases). |
||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,25 @@ namespace mamba | |
#ifndef _WIN32 | ||
namespace | ||
{ | ||
// `sigaddset` might be implemented as a macro calling `__sigbits(int)` function | ||
// At the same time `sigset_t` might be `unsigned int` | ||
// This causes compiler warning | ||
#pragma GCC diagnostic push | ||
#pragma GCC diagnostic ignored "-Wsign-conversion" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added comment explaining why this happens above Because, there is no bug, I completely disable this warning/error. |
||
|
||
sigset_t get_sigset() | ||
{ | ||
// block signals in this thread and subsequently | ||
// spawned threads | ||
sigset_t sigset; | ||
sigemptyset(&sigset); | ||
sigaddset(&sigset, SIGINT); | ||
// sigaddset(&sigset, SIGTERM); | ||
return sigset; | ||
} | ||
|
||
#pragma GCC diagnostic pop | ||
|
||
std::thread::native_handle_type sig_recv_thread; | ||
std::atomic<bool> receiver_exists(false); | ||
} | ||
|
@@ -74,12 +93,7 @@ namespace mamba | |
{ | ||
stop_receiver_thread(); | ||
|
||
// block signals in this thread and subsequently | ||
// spawned threads | ||
sigset_t sigset; | ||
sigemptyset(&sigset); | ||
sigaddset(&sigset, SIGINT); | ||
// sigaddset(&sigset, SIGTERM); | ||
sigset_t sigset = get_sigset(); | ||
pthread_sigmask(SIG_BLOCK, &sigset, nullptr); | ||
std::thread receiver(handler, sigset); | ||
sig_recv_thread = receiver.native_handle(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,7 +193,7 @@ namespace mamba::solver::libsolv | |
return { std::cref(it->second) }; | ||
} | ||
|
||
return specs::Channel::resolve(std::move(uc), channel_params()) | ||
return specs::Channel::resolve(uc, channel_params()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's |
||
.transform( | ||
[&](channel_list&& chan) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,14 @@ pybind11_add_module( | |
src/libmambapy/bindings/solver.cpp | ||
src/libmambapy/bindings/solver_libsolv.cpp | ||
) | ||
# TODO: remove when `SubdirData::cache_path()` is removed | ||
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") | ||
# This file uses capturing structured bindings, which was fixed in C++20 | ||
set_source_files_properties( | ||
src/libmambapy/bindings/legacy.cpp | ||
PROPERTIES COMPILE_FLAGS -Wno-error=deprecated-declarations | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I turned this back to warning. Sometimes it's useful to see when we're using deprecated functions, so let's have it as a warning. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes sense for that code or even the whole library. 👍🏽 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now, let's keep it for this file. If needed later, we can add this flag to the whole repo/lib I suppose. |
||
) | ||
endif() | ||
|
||
target_include_directories(bindings PRIVATE src/libmambapy/bindings) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good idea even if this will probably will make some untested toolchain fail.