Skip to content

Commit 80ae477

Browse files
maxwbuckleyclaude
andcommitted
Address review feedback: make -Werror opt-in, centralize warning flags
- Gate -Werror, -Wundef, -Wnull-dereference, -Wmissing-prototypes behind ROARING_WERROR option (OFF by default) so downstream builds are unaffected - Centralize warning flag variables (C_EXTRA_WARNING_FLAGS, AMALG_EXTRA_WARNING_FLAGS) in FindOptions.cmake - Simplify preprocessor guards: use #if defined(X) instead of #if defined(X) && X for macros guaranteed non-zero when defined - Add defined(__STDC_VERSION__) guard for -Wundef clean C++ compilation - Restore containers.c comments removed in previous commit Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3d84e07 commit 80ae477

File tree

8 files changed

+32
-27
lines changed

8 files changed

+32
-27
lines changed

CMakeLists.txt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ option(ROARING_LINK_STATIC "Link executables (tests, benchmarks) statically" OFF
4545
option(ROARING_BUILD_LTO "Build library with Link Time Optimization" OFF)
4646
option(ROARING_BUILD_C_AS_CPP "Build library C files using C++ compilation" OFF)
4747
option(ROARING_BUILD_C_TESTS_AS_CPP "Build test C files using C++ compilation" OFF)
48+
option(ROARING_WERROR "Treat warnings as errors (developer only)" OFF)
4849
option(ROARING_SANITIZE "Sanitize addresses" OFF)
4950
option(ROARING_SANITIZE_THREADS "Sanitize threads" OFF)
5051
option(ROARING_SANITIZE_UNDEFINED "Sanitize undefined behaviors" OFF)
@@ -146,21 +147,16 @@ if(ENABLE_ROARING_TESTS AND BASH AND NOT EMSCRIPTEN)
146147

147148
add_executable(amalgamate_demo $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/amalgamation_demo.c>)
148149
target_link_libraries(amalgamate_demo croaring-singleheader-include-source)
149-
# The amalgamation compiles everything in a single translation unit, which
150-
# gives GCC deeper interprocedural visibility and triggers false-positive
151-
# null-dereference warnings through allocation-failure paths. Suppress
152-
# this warning for amalgamation targets only; the library itself is still
153-
# checked with -Wnull-dereference in separate compilation units.
154-
if(NOT MSVC)
155-
target_compile_options(amalgamate_demo PRIVATE -Wno-null-dereference)
150+
if(AMALG_EXTRA_WARNING_FLAGS)
151+
target_compile_options(amalgamate_demo PRIVATE ${AMALG_EXTRA_WARNING_FLAGS})
156152
endif()
157153
add_test(amalgamate_demo amalgamate_demo)
158154

159155
add_library(croaring-singleheader-source-lib $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/roaring.c>)
160156
set_target_properties(croaring-singleheader-source-lib PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES)
161157
target_include_directories(croaring-singleheader-source-lib PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
162-
if(NOT MSVC)
163-
target_compile_options(croaring-singleheader-source-lib PRIVATE -Wno-null-dereference)
158+
if(AMALG_EXTRA_WARNING_FLAGS)
159+
target_compile_options(croaring-singleheader-source-lib PRIVATE ${AMALG_EXTRA_WARNING_FLAGS})
164160
endif()
165161

166162
add_executable(amalgamate_demo_cpp $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/amalgamation_demo.cpp>)

include/roaring/misc/configreport.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,14 @@ static inline void tellmeall() {
186186
(long unsigned int)sizeof(size_t),
187187
(long unsigned int)sizeof(int));
188188
}
189-
#if defined(__LITTLE_ENDIAN__) && __LITTLE_ENDIAN__
189+
#if defined(__LITTLE_ENDIAN__)
190190
// This is what we expect!
191191
// printf("you have little endian machine");
192192
#endif
193-
#if defined(__BIG_ENDIAN__) && __BIG_ENDIAN__
193+
#if defined(__BIG_ENDIAN__)
194194
printf("you have a big endian machine");
195195
#endif
196-
#if defined(__CHAR_BIT__) && __CHAR_BIT__
196+
#if defined(__CHAR_BIT__)
197197
if (__CHAR_BIT__ != 8) printf("on your machine, chars don't have 8bits???");
198198
#endif
199199
if (computecacheline() != 64)
@@ -217,14 +217,14 @@ static inline void tellmeall() {
217217
(long unsigned int)sizeof(size_t),
218218
(long unsigned int)sizeof(int));
219219
}
220-
#if defined(__LITTLE_ENDIAN__) && __LITTLE_ENDIAN__
220+
#if defined(__LITTLE_ENDIAN__)
221221
// This is what we expect!
222222
// printf("you have little endian machine");
223223
#endif
224-
#if defined(__BIG_ENDIAN__) && __BIG_ENDIAN__
224+
#if defined(__BIG_ENDIAN__)
225225
printf("you have a big endian machine");
226226
#endif
227-
#if defined(__CHAR_BIT__) && __CHAR_BIT__
227+
#if defined(__CHAR_BIT__)
228228
if (__CHAR_BIT__ != 8) printf("on your machine, chars don't have 8bits???");
229229
#endif
230230
}

include/roaring/portability.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ static inline int roaring_hamming(uint64_t x) {
471471
// We lack __has_include to check:
472472
#define CROARING_ATOMIC_IMPL CROARING_ATOMIC_IMPL_CPP
473473
#endif //__has_include
474-
#elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)
474+
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)
475475
#define CROARING_ATOMIC_IMPL CROARING_ATOMIC_IMPL_C
476476
#elif CROARING_REGULAR_VISUAL_STUDIO
477477
// https://www.technetworkhub.com/c11-atomics-in-visual-studio-2022-version-17/
@@ -584,7 +584,7 @@ static inline uint32_t croaring_refcount_get(const croaring_refcount_t *val) {
584584

585585
// We want to initialize structs to zero portably (C and C++), without
586586
// warnings. We can do mystruct s = CROARING_ZERO_INITIALIZER;
587-
#if defined(__cplusplus) && __cplusplus
587+
#if defined(__cplusplus)
588588
#define CROARING_ZERO_INITIALIZER \
589589
{}
590590
#else

src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ target_link_libraries(roaring PUBLIC "$<BUILD_INTERFACE:roaring-headers>")
6363
target_link_libraries(roaring PUBLIC "$<BUILD_INTERFACE:roaring-headers-cpp>")
6464

6565
target_include_directories(roaring PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
66-
if(NOT MSVC)
67-
target_compile_options(roaring PRIVATE $<$<COMPILE_LANGUAGE:C>:-Wmissing-prototypes>)
66+
if(C_EXTRA_WARNING_FLAGS)
67+
target_compile_options(roaring PRIVATE $<$<COMPILE_LANGUAGE:C>:${C_EXTRA_WARNING_FLAGS}>)
6868
endif()
6969

7070
#

src/containers/containers.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ extern bool container_iterator_prev(const container_t *c, uint8_t typecode,
5252
uint16_t *value);
5353
extern bool container_contains(
5454
const container_t *c, uint16_t val,
55-
uint8_t typecode);
55+
uint8_t typecode // !!! should be second argument?
56+
);
5657

5758
void container_free(container_t *c, uint8_t type) {
5859
switch (type) {
@@ -162,7 +163,7 @@ extern inline container_t *container_add(container_t *c, uint16_t val,
162163
uint8_t *new_typecode);
163164

164165
extern inline bool container_contains(const container_t *c, uint16_t val,
165-
uint8_t typecode);
166+
uint8_t typecode); // !!! 2nd arg?
166167

167168
extern inline container_t *container_and(const container_t *c1, uint8_t type1,
168169
const container_t *c2, uint8_t type2,

tests/cpp_unit.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ DEFINE_TEST(test_cpp_frozen_64) {
14761476
roaring_aligned_free(buf);
14771477
}
14781478

1479-
#if defined(ROARING_UNSAFE_FROZEN_TESTS) && ROARING_UNSAFE_FROZEN_TESTS
1479+
#if defined(ROARING_UNSAFE_FROZEN_TESTS)
14801480
// This test is unsafe, as it may trigger unaligned memory access
14811481
// It is only enabled if ROARING_UNSAFE_FROZEN_TESTS is defined.
14821482
DEFINE_TEST(test_cpp_frozen_portable) {
@@ -1553,7 +1553,7 @@ DEFINE_TEST(test_cpp_frozen_portable) {
15531553
}
15541554
#endif // ROARING_UNSAFE_FROZEN_TESTS
15551555

1556-
#if defined(ROARING_UNSAFE_FROZEN_TESTS) && ROARING_UNSAFE_FROZEN_TESTS
1556+
#if defined(ROARING_UNSAFE_FROZEN_TESTS)
15571557
// This test is unsafe, as it may trigger unaligned memory access
15581558
// It is only enabled if ROARING_UNSAFE_FROZEN_TESTS is defined.
15591559
DEFINE_TEST(test_cpp_frozen_64_portable) {
@@ -2215,7 +2215,7 @@ int main() {
22152215
cmocka_unit_test(test_cpp_bidirectional_iterator_64),
22162216
cmocka_unit_test(test_cpp_frozen),
22172217
cmocka_unit_test(test_cpp_frozen_64),
2218-
#if defined(ROARING_UNSAFE_FROZEN_TESTS) && ROARING_UNSAFE_FROZEN_TESTS
2218+
#if defined(ROARING_UNSAFE_FROZEN_TESTS)
22192219
cmocka_unit_test(test_cpp_frozen_portable),
22202220
cmocka_unit_test(test_cpp_frozen_64_portable),
22212221
#endif // ROARING_UNSAFE_FROZEN_TESTS

tests/toplevel_unit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4745,7 +4745,7 @@ DEFINE_TEST(test_frozen_serialization_max_containers) {
47454745
frozen_serialization_compare(r);
47464746
}
47474747

4748-
#if defined(ROARING_UNSAFE_FROZEN_TESTS) && ROARING_UNSAFE_FROZEN_TESTS
4748+
#if defined(ROARING_UNSAFE_FROZEN_TESTS)
47494749
// This test is unsafe, as it may trigger unaligned memory access
47504750
// It is only enabled if ROARING_UNSAFE_FROZEN_TESTS is defined.
47514751
DEFINE_TEST(test_portable_deserialize_frozen) {
@@ -5177,7 +5177,7 @@ int main() {
51775177
#if !CROARING_IS_BIG_ENDIAN
51785178
cmocka_unit_test(test_frozen_serialization),
51795179
cmocka_unit_test(test_frozen_serialization_max_containers),
5180-
#if defined(ROARING_UNSAFE_FROZEN_TESTS) && ROARING_UNSAFE_FROZEN_TESTS
5180+
#if defined(ROARING_UNSAFE_FROZEN_TESTS)
51815181
cmocka_unit_test(test_portable_deserialize_frozen),
51825182
#endif // ROARING_UNSAFE_FROZEN_TESTS
51835183
cmocka_unit_test(issue_15jan2024),

tools/cmake/FindOptions.cmake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,20 @@ endif()
2424
endif()
2525

2626
if(NOT MSVC)
27-
set(WARNING_FLAGS "-Wall -Werror -Wnull-dereference -Wundef")
27+
set(WARNING_FLAGS "-Wall")
2828
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
2929
set(WARNING_FLAGS "${WARNING_FLAGS} -Wmissing-braces -Wextra -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self")
3030
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
3131
set(WARNING_FLAGS "${WARNING_FLAGS} -Wextra -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wcast-align")
3232
endif()
33+
if(ROARING_WERROR)
34+
set(WARNING_FLAGS "${WARNING_FLAGS} -Werror -Wundef -Wnull-dereference")
35+
set(C_EXTRA_WARNING_FLAGS "-Wmissing-prototypes")
36+
# The amalgamation compiles everything in a single translation unit, which
37+
# gives GCC deeper interprocedural visibility and triggers false-positive
38+
# null-dereference warnings through allocation-failure paths.
39+
set(AMALG_EXTRA_WARNING_FLAGS -Wno-null-dereference)
40+
endif()
3341
endif()
3442

3543
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${STD_FLAGS} ${OPT_FLAGS} ${INCLUDE_FLAGS} ${WARNING_FLAGS} ")

0 commit comments

Comments
 (0)