• Jason Rhinelander's avatar
    Support binding noexcept function/methods in C++17 · 6e036e78
    Jason Rhinelander authored
    When compiling in C++17 mode the noexcept specifier is part of the
    function type.  This causes a failure in pybind11 because, by omitting
    a noexcept specifier when deducing function return and argument types,
    we are implicitly making `noexcept(false)` part of the type.
    
    This means that functions with `noexcept` fail to match the function
    templates in cpp_function (and other places), and we get compilation
    failure (we end up trying to fit it into the lambda function version,
    which fails since a function pointer has no `operator()`).
    
    We can, however, deduce the true/false `B` in noexcept(B), so we don't
    need to add a whole other set of overloads, but need to deduce the extra
    argument when under C++17.  That will *not* work under pre-C++17,
    however.
    
    This commit adds two macros to fix the problem: under C++17 (with the
    appropriate feature macro set) they provide an extra `bool NoExceptions`
    template argument and provide the `noexcept(NoExceptions)` deduced
    specifier.  Under pre-C++17 they expand to nothing.
    
    This is needed to compile pybind11 with gcc7 under -std=c++17.
    6e036e78
test_constants_and_functions.cpp 3.25 KB