-
-
Notifications
You must be signed in to change notification settings - Fork 190
Description
Hello,
OS: Ubuntu 22.04
jsoncons version: 1.2.0
compiler version: GNU 11.4.0
cmake version: 3.22.1
When using jsoncons in my project, I came across this warning (we use -Wnull-dereference and -Werror so it was treated as an error). Here's a minimal example to reproduce it:
main.cpp:
#include <jsoncons/json.hpp>
#include <jsoncons_ext/jsonschema/jsonschema.hpp>
int main() {
auto m_validator = jsoncons::jsonschema::make_json_schema(jsoncons::json::parse(""));
return 0;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
project(test_jsoncons)
add_executable(main main.cpp)
target_compile_options(main PRIVATE -Werror -Wnull-dereference)
mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release && make -j to reproduce.
It works fine if I omit -DCMAKE_BUILD_TYPE=Release.
Output:
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nico/Desktop/code/test_jsoncons/build
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
In member function ‘void jsoncons::basic_bigint<Allocator>::write_bytes_be(int&, std::vector<unsigned char, Alloc>&) const [with Alloc = std::allocator<unsigned char>; Allocator = std::allocator<unsigned char>]’:
cc1plus: error: null pointer dereference [-Werror=null-dereference]
cc1plus: all warnings being treated as errors
make[2]: *** [CMakeFiles/main.dir/build.make:76: CMakeFiles/main.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
I tried wrapping the include statements with
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnull-dereference"
// ...
#pragma GCC diagnostic pop
but it didn't work (it seems to be a known bug with GCC 11, fixed with GCC 13). Moving to GCC 13 is not an option for our project at the moment. Also tried adding the pragmas directly around the method write_bytes_be in jsoncons/utility/bigint.hpp but it did not work either.
For now we had to disable the Wnull-dereference flag until we move to GCC 13.
Not expecting anything on this, just thought I'd let you know.
Thanks in advance!