json icon indicating copy to clipboard operation
json copied to clipboard

Incompability between standalone mode and older boost libraries

Open doganulus opened this issue 4 years ago • 6 comments

I would like to report an edge case that there is some dependency left between standalone Boost::JSON library and older Boost libraries. Below is a minimal example failing to compile with BOOST_STATIC_ASSERT errors inside standard manylinux2014 docker environment, which is based on Centos7 having Boost v1.53 using g++9.3.

#include <iostream>
#include <boost/bimap/bimap.hpp> // From Boost 1.53. (The program compiles when removed.)

#define BOOST_JSON_STANDALONE 1
#include <boost/json.hpp> // From Boost::JSON 1.76.

int main(){

  auto ja = boost::json::array({1,2,3});
  std::cout << ja << std::endl;

  return 0;
}

The compilation produces several error messages such as:

/usr/local/include/boost/json/storage_ptr.hpp:491:39: error: macro "BOOST_STATIC_ASSERT" passed 2 arguments, but takes just 1
  491 |             memory_resource, T>::value);
      |                                       ^
In file included from /usr/include/boost/serialization/tracking.hpp:20,
                 from /usr/include/boost/serialization/nvp.hpp:32,
                 from /usr/include/boost/bimap/bimap.hpp:57,
                 from /workspaces/vevatools/data/bsa_example.cpp:4:
/usr/include/boost/static_assert.hpp:56: note: macro "BOOST_STATIC_ASSERT" defined here
   56 | #  define BOOST_STATIC_ASSERT( B ) static_assert(B, #B)

doganulus avatar Jul 23 '21 14:07 doganulus

You may be surprised to discover that I did not test Boost.JSON with every possible earlier version of Boost :) I'm not sure that this is a supported configuration. @glenfe ?

vinniefalco avatar Jul 23 '21 15:07 vinniefalco

You need to enclose the expression in parentheses.

pdimov avatar Jul 23 '21 16:07 pdimov

Although... why does Boost.JSON use BOOST_STATIC_ASSERT in standalone mode?

pdimov avatar Jul 23 '21 16:07 pdimov

It defines BOOST_STATIC_ASSERT if it doesn't exist, but it would better if it did not do this: https://github.com/boostorg/json/blob/master/include/boost/json/detail/config.hpp#L93-L95

Instead it could unconditionally use BOOST_JSON_STATIC_ASSERT which in non-standalone mode might make use of BOOST_STATIC_ASSERT.

glenfe avatar Jul 23 '21 23:07 glenfe

Ah this is with standalone Boost.JSON, which I suppose in theory should work with any other library. There are a few other boost macros that it defines in standalone.

vinniefalco avatar Jul 24 '21 00:07 vinniefalco

Same with all the other Boost macros - Boost.JSON shouldn't (re)define them.

pdimov avatar Jul 24 '21 01:07 pdimov

This was "solved" by removing the standalone mode.

grisumbras avatar Nov 16 '22 12:11 grisumbras