Closed
Description
Issue description
As the title says, I can't make overload_cast
to work with recent Intel compilers:
- icpc version 18.0.3 (gcc version 7.3.0 compatibility)
- icpc version 18.0.1 (gcc version 6.4.0 compatibility)
- icpc version 17.0.4 (gcc version 6.4.0 compatibility)
- icpc version 17.0.1 (gcc version 6.3.0 compatibility)
Reproducible example code
As a MWE, I've modified the cmake_example
to use overload_cast
and the latest release of pybind11:
#include <pybind11/pybind11.h>
int add(int i, int j) {
return i + j;
}
double add(double a, double b) {
return a + b;
}
namespace py = pybind11;
PYBIND11_MODULE(cmake_example, m) {
m.doc() = R"pbdoc(
Pybind11 example plugin
-----------------------
.. currentmodule:: cmake_example
.. autosummary::
:toctree: _generate
add
subtract
)pbdoc";
m.def("add", py::overload_cast<int, int>(&add), R"pbdoc(
Add two numbers
Some other explanation about the add function.
)pbdoc");
m.def("add", py::overload_cast<double, double>(&add), R"pbdoc(
Add two numbers
Some other explanation about the add function.
)pbdoc");
m.def("subtract", [](int i, int j) { return i - j; }, R"pbdoc(
Subtract two numbers
Some other explanation about the subtract function.
)pbdoc");
#ifdef VERSION_INFO
m.attr("__version__") = VERSION_INFO;
#else
m.attr("__version__") = "dev";
#endif
}
I configure with cmake -H. -Bbuild -DCMAKE_CXX_COMPILER=icpc -DCMAKE_C_COMPILER=icc -DCMAKE_CXX_STANDARD=14
and I invariably get:
Scanning dependencies of target cmake_example
[ 50%] Building CXX object CMakeFiles/cmake_example.dir/src/main.cpp.o
/cluster/home/roberto/Workspace/robertodr/cmake_example/pybind11/include/pybind11/detail/common.h(755): error: static assertion failed with "pybind11::overload_cast<...> requires compiling in C++14 mode"
static_assert(detail::deferred_t<std::false_type, Args...>::value,
^
detected during instantiation of class "pybind11::overload_cast<Args...> [with Args=<int, int>]" at line 27 of "/cluster/home/roberto/Workspace/robertodr/cmake_example/src/main.cpp"
This seems to be due to the fact that PYBIND11_CPP14
is never defined for the Intel compilers in detail/common.h
I added the following lines to the CMakeLists.txt
to remedy for that:
target_compile_definitions(cmake_example
PRIVATE
$<$<CXX_COMPILER_ID:Intel>:PYBIND11_CPP14>
)
Now I get the following error for toolchains 1 and 2 above:
Scanning dependencies of target cmake_example
[ 50%] Building CXX object CMakeFiles/cmake_example.dir/src/main.cpp.o
/cluster/home/roberto/Workspace/robertodr/cmake_example/pybind11/include/pybind11/detail/descr.h(74): error: expression must have a constant value
static constexpr auto digits = descr<sizeof...(Digits), 0>({ ('0' + Digits)..., '\0' }, { nullptr });
this error for toolchain 4:
In file included from /cluster/home/roberto/Workspace/robertodr/cmake_example/pybind11/include/pybind11/attr.h(13),
from /cluster/home/roberto/Workspace/robertodr/cmake_example/pybind11/include/pybind11/pybind11.h(43),
from /cluster/home/roberto/Workspace/robertodr/cmake_example/src/main.cpp(1):
/cluster/home/roberto/Workspace/robertodr/cmake_example/pybind11/include/pybind11/cast.h(838): error: alias template "pybind11::detail::type_caster_base<type>::cast_op_type" may not be used in the type-id of the alias-declaration
template <typename T> using cast_op_type = cast_op_type<T>;
but no error for toolchain 3.
To summarize:
- The
PYBIND11_CPP14
preprocessor variable should be defined for the Intel compilers. - The 2018 releases of the Intel compilers I have access to do not work with C++14.
For the latter, I can't suggest a solution, but I'd be glad to test anything you might suggest.
Metadata
Metadata
Assignees
Labels
No labels