Skip to content

Commit 3a7e06c

Browse files
committed
src: Add sign-compare warnings to clang
For a while, GCC has generated warnings about sign errors. A common mistake if compiling with clang was to accidentally introduce signedness errors, which were picked up by the GCC builds. This occurs due to an inconsistency in -Wall implementation between clang and gcc: gcc includes sign-compare, clang does not. See: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wall vs https://clang.llvm.org/docs/DiagnosticsReference.html#wall Note that sign-compare is included under -Wextra for clang: https://clang.llvm.org/docs/DiagnosticsReference.html#wextra Clang will now generate similar warnings with -Wsign-compare: https://clang.llvm.org/docs/DiagnosticsReference.html#wsign-compare Interestingly, if specified on its own, -Wsign-compare will include C, whereas gcc -Wall affects C++ only. Therefore we must work around this in the make file to emulate the GCC behaviour in clang builds. Also fix a couple of warnings found in some tests. Signed-off-by: Alex Ainscow <[email protected]>
1 parent 50342c1 commit 3a7e06c

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ if(NOT MSVC)
113113
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-ignored-qualifiers>)
114114
endif()
115115

116+
if (CMAKE_CXX_COMPILER_ID STREQUAL Clang)
117+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wsign-compare>)
118+
endif()
119+
116120
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-ftemplate-depth-1024>)
117121

118122
# Because Boost can't be bothered to not include its own deprecated headers

src/test/osd/TestECBackend.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ class ErasureCodeDummyImpl : public ErasureCodeInterface {
158158
// for each missing shard.
159159
for (auto a : available) {
160160
minimum_set.insert(a);
161-
if (minimum_set.size() == data_chunk_count) {
161+
if (std::cmp_equal(minimum_set.size(), data_chunk_count)) {
162162
break;
163163
}
164164
}
165165

166-
if (minimum_set.size() != data_chunk_count) {
166+
if (std::cmp_not_equal(minimum_set.size(), data_chunk_count)) {
167167
minimum_set.clear();
168168
return -EIO; // Cannot recover.
169169
}
@@ -174,7 +174,6 @@ class ErasureCodeDummyImpl : public ErasureCodeInterface {
174174
}
175175
return 0;
176176
}
177-
178177
[[deprecated]]
179178
int minimum_to_decode(const std::set<int> &want_to_read,
180179
const std::set<int> &available,

src/test/osd/test_scrubber_be.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class TestPg : public PgScrubBeListener {
118118
}
119119

120120
for (shard_id_t i; i < get_ec_sinfo().get_k(); ++i) {
121-
for (int j = 0; j < get_ec_sinfo().get_chunk_size(); j++) {
121+
for (int j = 0; std::cmp_less(j, get_ec_sinfo().get_chunk_size()); j++) {
122122
encode_map.at(i).c_str()[j] =
123123
chunks[j + (get_ec_sinfo().get_chunk_size() * i.id)];
124124
for (shard_id_t k{static_cast<int8_t>(get_ec_sinfo().get_k_plus_m())};

0 commit comments

Comments
 (0)