Issue with Boost.Json library

352 Views Asked by At

Could somebody help me with error I am getting when including:

#include <boost/json/src.hpp>

Error is:

In file included from /usr/local/include/boost/json/src.hpp:27:
In file included from /usr/local/include/boost/json.hpp:15:
In file included from /usr/local/include/boost/json/array.hpp:16:
In file included from /usr/local/include/boost/json/storage_ptr.hpp:14:
In file included from /usr/local/include/boost/json/memory_resource.hpp:16:
/usr/local/include/boost/container/pmr/polymorphic_allocator.hpp:132:23: error: expected a class name after '~' to name a destructor
   {  (void)p; p->~U(); }

My CMake config has:

find_package(Boost 1.80.0 REQUIRED COMPONENTS timer json)

and

target_link_libraries(device_monitor
        Boost::timer
        Boost::json
        )
1

There are 1 best solutions below

0
On

Apparently somewhere you have defined U as something else. Preprocessor macros are unsanitary like that, so avoid it.

My guesses are that you are on some kind of Windows platform and U() is a macro that "smart" wraps a string literal of some kind (e.g. to do some UNICODE-depedent stuff or translation).

You could easily show us that in a minimal self-contained example, or go ahead and figure it out by using CMake to precompile the translation unit for you, e.g. something like cmake --build build test.cpp.i. You will find out what the compiler sees instead of the intended code.

You can also demonstrate this effect by

  • moving the boost include to the top
  • disabling precompiled headers if you are using them