Build with C++20
Asio needs a definition to build with C++20, link to bug in comment.
The compiler also complained that it now needs full definition of enum_
inside in leaf_data_helpers.hpp:createEnum. One would think that that
would be the case even before, because the lambda uses it in a context
that requires full definition (i.e. creating an instance). However, the
lambda is a generic lambda, which means it's a template. The C++
standard says (put very simply) "compilation of templates can be
deferred until the end of a translation unit". And, because
leaf_data_helpers is a header, it is possible that the definition enum_
comes in another included file after leaf_data_helpers.hpp, which means,
by the time the compiler is compiling the generic lambda, it already has
a definition for enum_.
Now, in C++20, std::transform is constexpr. The standard says, that
compilers can NOT use this deferring mechanic when dealing with
constexpr function, so it needs the definition immediately, which means
that ast_values.hpp has to be included inside leaf_data_helpers.
This probably wouldn't have happened if I defined the function inside a
cpp file (even clang-tidy warns for this).
tl;dr: the generic lambda in createEnum didn't need the enum_ definition
immediately, but now, std::transform is constexpr and that means the
definition IS needed immediately
https://timsong-cpp.github.io/cppwp/n4659/temp.point#8 is where it says
about the templates. Thanks to PJBoy on freenode.#c++ for explaining
this to me.
Change-Id: I4675643572db37233a88f7a7ee3570fabb897dad
diff --git a/CMakeLists.txt b/CMakeLists.txt
index df78b3c..e61c6c6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,6 @@
project(netconf-cli LANGUAGES CXX)
cmake_minimum_required(VERSION 3.0)
-set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
@@ -56,6 +56,9 @@
find_package(docopt REQUIRED)
find_package(Boost REQUIRED COMPONENTS filesystem)
+# Fixes C++20 build
+# https://github.com/boostorg/asio/issues/312
+add_definitions(-DBOOST_ASIO_DISABLE_CONCEPTS)
find_library(REPLXX_LIBRARY NAMES replxx replxx-d REQUIRED)
find_path(REPLXX_PATH replxx.hxx)
if("${REPLXX_PATH}" STREQUAL REPLXX_PATH-NOTFOUND)
@@ -365,7 +368,7 @@
option(WITH_PYTHON_BINDINGS "Create and install Python3 bindings for accessing datastores" OFF)
if(WITH_PYTHON_BINDINGS)
- set(PYBIND11_CPP_STANDARD -std=c++17)
+ set(PYBIND11_CPP_STANDARD -std=c++20)
find_package(pybind11 REQUIRED)
pybind11_add_module(netconf_cli_py src/python_netconf.cpp)
target_link_libraries(netconf_cli_py PUBLIC netconfaccess)
diff --git a/tests/leaf_data_helpers.hpp b/tests/leaf_data_helpers.hpp
index 0a28ae3..91eb3f2 100644
--- a/tests/leaf_data_helpers.hpp
+++ b/tests/leaf_data_helpers.hpp
@@ -1,4 +1,5 @@
#include <algorithm>
+#include "ast_values.hpp"
#include "leaf_data_type.hpp"
yang::Enum createEnum(const std::initializer_list<const char*>& list)
{