diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 9bb27d7ac2..7753d8f0d2 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -1329,14 +1329,18 @@ object object_or_cast(T &&o) { return pybind11::cast(std::forward(o)); } + +#if defined(PYBIND11_CPP17) // Declared in pytypes.h: // Written here so make_caster can be used template template str_attr_accessor object_api::attr_with_type(const char *key) const { - annotations()[key] = make_caster::name.text; + static constexpr auto name = make_caster::name; + annotations()[key] = name.text; return {derived(), key}; } +#endif // Placeholder type for the unneeded (and dead code) static variable in the // PYBIND11_OVERRIDE_OVERRIDE macro diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index feb18ac638..89afe22136 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -113,10 +113,11 @@ class object_api : public pyobject_tag { /// See above (the only difference is that the key is provided as a string literal) str_attr_accessor attr(const char *key) const; +#if defined(PYBIND11_CPP17) // attr_with_type is implemented in cast.h: template str_attr_accessor attr_with_type(const char *key) const; - +#endif /** \rst Matches * unpacking in Python, e.g. to unpack arguments out of a ``tuple`` or ``list`` for a function call. Applying another * to the result yields