check for already existing enum value added; added test (#1453)

* check for already existing enum value added; added test

* added enum value name to exception message

* test for defining enum with multiple identical names moved to test_enum.cpp/py
This commit is contained in:
Krzysztof Fornalczyk
2018-09-11 10:59:56 +02:00
committed by Wenzel Jakob
parent 35c82c7250
commit 5c8746ff13
3 changed files with 24 additions and 1 deletions

View File

@@ -1463,7 +1463,10 @@ public:
enum_& value(char const* name, Type value, const char *doc = nullptr) {
auto v = pybind11::cast(value, return_value_policy::copy);
this->attr(name) = v;
m_entries[pybind11::str(name)] = std::make_pair(v, doc);
auto name_converted = pybind11::str(name);
if (m_entries.contains(name_converted))
throw value_error("Enum error - element with name: " + std::string(name) + " already exists");
m_entries[name_converted] = std::make_pair(v, doc);
return *this;
}