From cd4f771b124022608129d3874701e0ccb3e7b106 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 20 Dec 2024 12:30:27 -0800 Subject: [PATCH] Swap order of attr_with_type_hint implementation in cast.h (so that the `const char *` overload appears first). --- include/pybind11/cast.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 69fc0bada..82ec2b6d0 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -1371,6 +1371,22 @@ using py_str = str; // Declared in pytypes.h: // Written here so make_caster can be used +template +template +str_attr_accessor object_api::attr_with_type_hint(const char *key) const { +#if !defined(__cpp_inline_variables) + static_assert(!std::is_same::value, + "C++17 feature __cpp_inline_variables not available: " + "https://en.cppreference.com/w/cpp/language/static#Static_data_members"); +#endif + object ann = annotations(); + if (ann.contains(key)) { + throw std::runtime_error("__annotations__[\"" + std::string(key) + "\"] was set already."); + } + ann[key] = make_caster::name.text; + return {derived(), key}; +} + template template obj_attr_accessor object_api::attr_with_type_hint(handle key) const { @@ -1389,22 +1405,6 @@ obj_attr_accessor object_api::attr_with_type_hint(handle key) const { return {derived(), reinterpreted_key}; } -template -template -str_attr_accessor object_api::attr_with_type_hint(const char *key) const { -#if !defined(__cpp_inline_variables) - static_assert(!std::is_same::value, - "C++17 feature __cpp_inline_variables not available: " - "https://en.cppreference.com/w/cpp/language/static#Static_data_members"); -#endif - object ann = annotations(); - if (ann.contains(key)) { - throw std::runtime_error("__annotations__[\"" + std::string(key) + "\"] was set already."); - } - ann[key] = make_caster::name.text; - return {derived(), key}; -} - // Placeholder type for the unneeded (and dead code) static variable in the // PYBIND11_OVERRIDE_OVERRIDE macro struct override_unused {};