Skip to content
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

Casting out-of-range int to enum (class) is UB #69

Closed
SX91 opened this issue Dec 26, 2017 · 4 comments
Closed

Casting out-of-range int to enum (class) is UB #69

SX91 opened this issue Dec 26, 2017 · 4 comments

Comments

@SX91
Copy link
Contributor

SX91 commented Dec 26, 2017

Undefined behavior or undefined value, actually. Is it really a good idea to allow parsing to enums by simply casting integers?

@SX91 SX91 changed the title Casting int to enum (class) is UB Casting out-of-range int to enum (class) is UB Dec 26, 2017
@henryiii
Copy link
Collaborator

Any ideas on a fix?

@SX91
Copy link
Contributor Author

SX91 commented Apr 4, 2018

That can't be easily fixed without removal of casting num to enum. I've removed this functionality in my local project and made hard requirement on operator<< for enums (so enum should be parsable for automatic cast).
Anyway, casting num to enum is a bad idea anyway, so either this ^ or require user to pass num->enum convert function/lambda.

@SX91 SX91 mentioned this issue Apr 6, 2018
@henryiii
Copy link
Collaborator

henryiii commented Apr 6, 2018

Do you have a PR or a diff of the changes? That sounds reasonable.

Edit: I see what you mean; this was rewritten by a PR; operator << wasn't originally used.

@henryiii
Copy link
Collaborator

henryiii commented Apr 7, 2018

Let me know if that didn't fix it!

@henryiii henryiii closed this as completed Apr 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants