-
Notifications
You must be signed in to change notification settings - Fork 274
Correctly interpret underlying type specification of enums #5441
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
Conversation
b862db3
to
a64235e
Compare
a64235e
to
775a449
Compare
src/ansi-c/c_typecheck_type.cpp
Outdated
{ | ||
error().source_location = source_location; | ||
error() << "underlying type for enum must be an integral type" << eom; | ||
throw 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not have a structured exception to throw here? (and in the other cases below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this should an invalid_source_file_exceptiont
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, and thanks for the comprehensive test cases. A couple of minor nitpicks really:
- Error handling - we put quite a big effort into cleaning up error handling, adding structured exceptions, things like that - so it would be good to avoid the
throw 0
if possible. - What error messages does clang emit for the "non-integral underlying type" and "underlying type too narrow for constant" cases? It would be good to make our error messages broadly similar just for ease of users googling for help if they hit them, etc.
{ | ||
warning().source_location = source_location; | ||
warning() << "ignoring specification of underlying type for enum" << eom; | ||
typecheck_type(type.add_type(ID_enum_underlying_type)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using add_something
to refer to something that's already there is pretty oof.
|
||
enum enum1 : unsigned char | ||
{ | ||
E1 = 256 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good test case to include!
@chrisr-diffblue Current errors for these cases in clang look like this:
and
I think the existing error messages we have here are sufficiently close to that. We could include some extra information like what we think the underlying type is and why it doesn't fit and such, but I wouldn't call this a blocker. |
I'm OK with these changes though I'd also prefer if we didn't proliferate the |
775a449
to
875bf69
Compare
Thanks @hannes-steffenhagen-diffblue - @danpoe If it's not too much of a pain, could you model the error messages on the above? In particular, showing the user the type like that its quite helpful to them. |
Codecov Report
@@ Coverage Diff @@
## develop #5441 +/- ##
===========================================
- Coverage 68.21% 67.38% -0.84%
===========================================
Files 1178 1178
Lines 97561 97580 +19
===========================================
- Hits 66554 65750 -804
- Misses 31007 31830 +823
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
875bf69
to
5f3519a
Compare
Ok, changed the error messages to a text similar to the clang messages and including the type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing my nitpicks :-)
Uh oh!
There was an error while loading. Please reload this page.