Page MenuHomePhabricator

[clang-tidy] Don't use assignment for value-initialized enums

Authored by malcolm.parsons on Feb 6 2019, 2:59 PM.



The modernize-use-default-member-init check crashes when trying to
create an assignment value for a value-initialized enum because it isn't a
An enum cannot be initialized by assigning 0 to it unless a cast is added.
It could be initialized with an enumerator with the value 0, but there might not
be one.
Avoid these issues by ignoring the UseAssignment setting for value-initialized

Fixes PR35050.

Diff Detail

Event Timeline

malcolm.parsons created this revision.Feb 6 2019, 2:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 6 2019, 2:59 PM

How are the semantics for enum class in this case?

172 ↗(On Diff #185649)

What happens for the case enum Enum { Foo = 3 }; /* ... */ : e() /* ... */, is that even well formed?
I feel a testcase along those lines is missing.

malcolm.parsons marked an inline comment as done.Feb 7 2019, 6:48 AM

How are the semantics for enum class in this case?

No enumerators are present in the initialisation or the fixit, so there is no difference.

172 ↗(On Diff #185649)

There are no errors or warnings from gcc or clang for that code.
Adding a testcase wouldn't increase coverage.

This revision is now accepted and ready to land.Feb 8 2019, 3:52 AM
This revision was automatically updated to reflect the committed changes.