mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-19 22:39:09 +00:00
* Fix for Issue #1258 list_caster::load method will now check for a Python string and prevent its automatic conversion to a list. This should fix the issue "pybind11/stl.h converts string to vector<string> #1258" (https://github.com/pybind/pybind11/issues/1258) * Added tests for fix of issue #1258 * Changelog: stl string auto-conversion
This commit is contained in:
@@ -11,6 +11,9 @@
|
||||
#include "constructor_stats.h"
|
||||
#include <pybind11/stl.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
// Test with `std::variant` in C++17 mode, or with `boost::variant` in C++11/14
|
||||
#if PYBIND11_HAS_VARIANT
|
||||
using std::variant;
|
||||
@@ -33,6 +36,8 @@ struct visit_helper<boost::variant> {
|
||||
}} // namespace pybind11::detail
|
||||
#endif
|
||||
|
||||
PYBIND11_MAKE_OPAQUE(std::vector<std::string, std::allocator<std::string>>);
|
||||
|
||||
/// Issue #528: templated constructor
|
||||
struct TplCtorClass {
|
||||
template <typename T> TplCtorClass(const T &) { }
|
||||
@@ -237,6 +242,11 @@ TEST_SUBMODULE(stl, m) {
|
||||
// test_stl_pass_by_pointer
|
||||
m.def("stl_pass_by_pointer", [](std::vector<int>* v) { return *v; }, "v"_a=nullptr);
|
||||
|
||||
// #1258: pybind11/stl.h converts string to vector<string>
|
||||
m.def("func_with_string_or_vector_string_arg_overload", [](std::vector<std::string>) { return 1; });
|
||||
m.def("func_with_string_or_vector_string_arg_overload", [](std::list<std::string>) { return 2; });
|
||||
m.def("func_with_string_or_vector_string_arg_overload", [](std::string) { return 3; });
|
||||
|
||||
class Placeholder {
|
||||
public:
|
||||
Placeholder() { print_created(this); }
|
||||
|
||||
Reference in New Issue
Block a user