I am trying to compile from source and experiment with the examples in boost::sml
. The visitor example in particular will not compile, so my application with sml
is missing a straightforward way to just status which states its state machines are in.
I am running on a machine with the following statuses when doing the initial cmake setup:
-- The CXX compiler identification is GNU 7.5.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test HAS_CXX14_FLAG
-- Performing Test HAS_CXX14_FLAG - Success
-- Performing Test HAS_CXX17_FLAG
-- Performing Test HAS_CXX17_FLAG - Success
-- Performing Test HAS_CXX20_FLAG
-- Performing Test HAS_CXX20_FLAG - Failed
-- Boost version: 1.65.1
-- Configuring done
-- Generating done
Most of the code compiles, but for example/visitor.cpp
, I get these errors:
In file included from /data/sml/example/visitor.cpp:8:0:
/data/sml/include/boost/sml.hpp: In instantiation of ‘struct boost::ext::sml::v1_1_4::back::sm_impl<boost::ext::sml::v1_1_4::back::sm_policy<state_name_visitor<boost::ext::sml::v1_1_4::back::sm<boost::ext::sml::v1_1_4::back::sm_policy<composite> > > > >’:
/data/sml/include/boost/sml.hpp:1789:72: required from ‘boost::ext::sml::v1_1_4::back::sm< <template-parameter-1-1> >::operator T&() [with T = state_name_visitor<boost::ext::sml::v1_1_4::back::sm<boost::ext::sml::v1_1_4::back::sm_policy<composite> > >; TSM = boost::ext::sml::v1_1_4::back::sm_policy<composite>]’
/data/sml/example/visitor.cpp:68:62: required from here
/data/sml/include/boost/sml.hpp:1362:68: error: no matching function for call to ‘state_name_visitor<boost::ext::sml::v1_1_4::back::sm<boost::ext::sml::v1_1_4::back::sm_policy<composite> > >::operator()()’
compilation terminated due to -Wfatal-errors.
Any suggestions? Is C++20 required?
C++20 is not required. The current revision on Github contains:
#error "[Boost::ext].SML requires C++14 support (Clang-3.4+, GCC-5.1+, MSVC-2015+)"
And indeed, it compiles fine with -std=c++14, even with GCC 7.5 on my Ubuntu 18.04 box.
However, since your CMake output suggests that C++17 is selected, I tried, and that gives the same problem. I might try to find a fix (after dinner)
I cannot say I fully understand this, but the following change makes it work:
const auto state_name = state_name_visitor<decltype(sm)>{sm};
Should be
const auto state_name = state_name_visitor<decltype((sm))>{sm};
Or alternatively
const auto state_name = state_name_visitor<decltype(sm)&>{sm};
Now it compiles in C++17 mode on GCC 7.5.