danielaparker / jsoncons

A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON
https://danielaparker.github.io/jsoncons
Other
699 stars 158 forks source link

compile error when define _GLIBCXX_USE_CXX11_ABI=0 #429

Closed lilothar closed 1 year ago

lilothar commented 1 year ago

Describe the bug when I define the _GLIBCXX_USE_CXX11_ABI=0 and compile, it raise this no matching function for call to ‘FreeListAllocator::FreeListAllocator()’

Enumerate the steps to reproduce the bug

Include a small, self-contained example if possible

What compiler, architecture, and operating system?

What jsoncons library version?

danielaparker commented 1 year ago

In what context are you observing this? Are you trying to compile one of the jsoncons examples that use FreeListAllocator? Or run the unit tests?

lilothar commented 1 year ago

thanks for answer me! I have a import a project(tensorflow) that compiled with define _GLIBCXX_USE_CXX11_ABI=0, so I try test jsoncon build with the same defines, it cause this error, I have fix it with add a constructor with it:

#if _GLIBCXX_USE_CXX11_ABI==0  
FreeListAllocator() {}
#endif  //_GLIBCXX_USE_CXX11_ABI==0  

then it will work and test fine

it is easy to recurrent add below to CMakeList.txt

ADD_DEFINITIONS(-D_GLIBCXX_USE_CXX11_ABI=0)

both the test and example Will report the same error

danielaparker commented 1 year ago

I believe the issue is that the old gcc COW string (enabled by _GLIBCXX_USE_CXX11_ABI=0) is incompatible with allocators that are not default constructible, which are allowed in C++ 11. The jsoncons test suite includes four files that have tests with the non-default constructible allocator FreeListAllocator. These tests wouldn't be expected to compile with _GLIBCXX_USE_CXX11_ABI=0, what we can do in our next release is #if out these tests for the case _GLIBCXX_USE_CXX11_ABI=0.

In the meantime, I would suggest continuing with your hack that adds a default constructor. You won't be using non-default constructible allocators anyway, and don't need to test them.