diff --git a/include/pybind11/detail/descr.h b/include/pybind11/detail/descr.h index 357e45be3f..6a30b29bc4 100644 --- a/include/pybind11/detail/descr.h +++ b/include/pybind11/detail/descr.h @@ -238,12 +238,26 @@ constexpr descr concat(const descr &descr) { return descr; } +#if defined(PYBIND11_CPP17) +template +constexpr descr operator,(const descr &a, + const descr &b) { + // Ensure that src_loc of existing descr is used. + return a + const_name(", ", src_loc{nullptr, 0}) + b; +} + +template +constexpr auto concat(const descr &d, const Args &...args) { + return (d, ..., args); +} +#else template constexpr auto concat(const descr &d, const Args &...args) -> decltype(std::declval>() + concat(args...)) { // Ensure that src_loc of existing descr is used. return d + const_name(", ", src_loc{nullptr, 0}) + concat(args...); } +#endif template constexpr descr type_descr(const descr &descr) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3a1ce8949d..12b258086a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -130,6 +130,7 @@ set(PYBIND11_TEST_FILES test_class_sh_mi_thunks test_class_sh_module_local.py test_class_sh_property + test_class_sh_property_non_owning test_class_sh_shared_ptr_copy_move test_class_sh_trampoline_basic test_class_sh_trampoline_self_life_support diff --git a/tests/test_class_sh_property_non_owning.cpp b/tests/test_class_sh_property_non_owning.cpp index 5be72007be..d15bf23a79 100644 --- a/tests/test_class_sh_property_non_owning.cpp +++ b/tests/test_class_sh_property_non_owning.cpp @@ -27,10 +27,10 @@ struct DataFieldsHolder { std::vector vec; public: - DataFieldsHolder(std::size_t vec_size) { + explicit DataFieldsHolder(std::size_t vec_size) { for (std::size_t i = 0; i < vec_size; i++) { int i11 = static_cast(i) * 11; - vec.push_back(DataField(13 + i11, 14 + i11, 15 + i11)); + vec.emplace_back(13 + i11, 14 + i11, 15 + i11); } }