-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Defining enum with mutiple identical values should cause an error #1451
Comments
/// Add an enumeration entry
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);
return *this;
} This is what |
Should be a simple enough check if you want to submit a PR (and turn your original post into a test case): pybind11::str pyname(name);
if (m_entries.contains(pyname))
throw value_error("...");
// ... (current code) |
I've created a pull request - #1453 |
I've fixed formatting issues, but still travis fails for XCode 9 C++ ( https://travis-ci.org/pybind/pybind11/builds/404210394 ). For me it looks a bit like configuration issue, @jagerman @bstaletic could you have a look at it? |
PR merged. Closing. |
It's quite easy to make the following mistake:
This code compiles fine without any error/warning. When the module is loaded in Python, you can access only first value of SimpleEnum - "ONE". Would it be possible to make this code throw an error or at least warning at compile time (or eventually during loading python module) ?
Other information:
Pybind version: 2.2.3, Win 10 x64, Visual Studio 2015 x64, Python: Anaconda Python 3.6.5
The text was updated successfully, but these errors were encountered: