Closed
Description
Description
At line 260 in cmake/test.cmake
there is this code
include(CheckTypeSize)
check_type_size("size_t" sizeof_size_t LANGUAGE CXX)
if(sizeof_size_t AND ${sizeof_size_t} EQUAL 4)
message(STATUS "Auto-enabling 32bit unit test.")
set(${build_32bit_var} ON)
else()
set(${build_32bit_var} OFF)
endif()
The conditional check
if(sizeof_size_t AND ${sizeof_size_t} EQUAL 4)
The first condition if(sizeof_size_t
is always TRUE, since it is comparing against the string value "sizeof_size_t". To check if the string is empty (meaning check_type_size could not return a value for size_t) it should be
if(${sizeof_size_t} AND ${sizeof_size_t} EQUAL 4)
If for some reason the size of size_t is unknown (for example, using exotic toolchains where stddef.h might not be visible during the initial cmake evaluation) this will cause the invocation of cmake
to fail.
Reproduction steps
Replace the call to check_type_size
with
set(sizeof_size_t "")
Expected vs. actual results
Running cmake .
should not fail.
Minimal code example
No response
Error messages
if given arguments:
"sizeof_size_t" "AND" "EQUAL" "4"
Unknown arguments specified
### Compiler and operating system
gcc 11.2.0, Linux
### Library version
3.11.2
### Validation
- [X] The bug also occurs if the latest version from the [`develop`](https://github.com/nlohmann/json/tree/develop) branch is used.
- [ ] I can successfully [compile and run the unit tests](https://github.com/nlohmann/json#execute-unit-tests).