-
Notifications
You must be signed in to change notification settings - Fork 21
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
MSVC Code Analysis warnings suggesting enum class
#319
Comments
Some notes that may help with automated changes: From
Flags:
Regexp:
That will extract all names that follow an The result is redirected to a file for later processing. From the fix branch: A list of prefixed enum values can be obtained with:
Flags (
The Regexp:
Since many enum values are used more than once, they will be found more than once. Hence we must The output file will have a couple of extraneous lines from a comment that was matched. These can be manually removed:
More to follow later.... |
Or just use Visual Assist's |
I found something that largely works, using the input files generated above:
It will go through each enum name, and do a global search/replace of all enum values to add the prefix. It then does a test build, and it that succeeds, it creates a commit with an automatic commit message. There was one snag with One other slight issue, is a similar case happened in comments, where comment text was prefixed with an enum name. It doesn't break the code, so the compile step still succeeded, but the result looks ugly. Comments were edited by:
These were found afterwards using:
Diff lines containing additions, with a comment, and the scope resolution operator added after the comment. |
Bit of an update. I noticed a few entries were missing from the enum values list I had extracted earlier. This resulted in unprefixed values in the auto processed results. Additionally, I needed to adjust the text replacement command to account for multiple replacements in one line. The enum values previously missing were:
I manually added those to the file, and re-ran the processing command. The updated processing command was:
Additionally, the output was checked by temporarily switching all
This results in PR #371. Once the branch for #371 was made, I then rebased existing changes from PR #368 on top of it, forcing merge conflicts to resolve to the original code. This effectively cut down the bulk of the remaining code, as only the non-prefix-addition changes still remained. The result of this was pushed as branch Git rebase command:
Confusingly, I also went and undid some of the accidental whitespace changes. I might not have caught all whitespace changes, but I did To check the whitespace changes, I used the following searches:
The "+" was to find new added lines in the diff, which after some whitespace, contained some known changed pattern. |
What is the status of this issue, am I ok to slowly moving towards scoped enums or is there still a push to try and do it as a single large commit? |
So far, enum name scope prefixes have been added to all enum value names (required for Still to change is actually adding the During the previous attempt, it was discovered a lot of We may need to discuss cases that would rely on heavy |
To be fair, the casting is ... well, it's hideous. It's what happens when I want to "just get something our the door". In many cases a table lookup is a better option and will require some refactoring to get it looking good and functioning properly. Anyway, I'm definitely in favor of moving toward |
Ahh, to add some clarity, switching from For enums that are meant to be used as table lookup, we'd probably want to refactor to add a type conversion operator, or we might want to look into refactoring the code so it doesn't use enum value names in table lookups. |
I would be interested to see how the type conversion operator works out if appropriate for some of the enums. |
I found this article interesting: It's more about bit manipulation operators, rather than type conversion operators, but the idea should be similar. There is the use of a macro near the end, to shorten enabling bit operators for enum classes. Maybe we want to avoid that part. Its been a while since I read the article, so I don't quite remember how big of a deal it was. I don't think it was super important. |
I was looking to scope the enums ConnectorDir and StructureID. They are both used with the mStructures.addItem(constants::WAREHOUSE, 9, StructureID::SID_WAREHOUSE);
mConnections.addItem(constants::AG_TUBE_INTERSECTION, 110, ConnectorDir::CONNECTOR_INTERSECTION); I'm not sure if anyone has a good idea for how to store the metadata in a way that doesn't require static_cast into and out of int for the two enums. (Maybe some sort of redesign to If we don't want to change using example: namespace ConnectorDir
{
enum ConnectorDir
{
Intersection = 1,
Right,
Left,
Vertical // Functions as an intersection
};
} |
Ok, looks like you've identified one of the more problematic cases. Perhaps we should look at this code and see if there is a way to redesign it. Wrapping it in a namespace would ensure uses of the value names have to be scope prefixed. Though I suspect it would do nothing to eliminate the MSVC warning. Maybe in the future we won't need an |
It appears there are currently only 3
They are somewhat large and extensively used though, so perhaps more difficult to update than previous ones. |
Running MSVC's Code Analysis (Analyze -> Run Code Analysis -> On Solution) gives many warnings, most of which suggest changing
enum
toenum class
.Warnings filtered for
enum class
suggestions:As a side note, some of those paths have inconsistencies in the casing. In particular:
The text was updated successfully, but these errors were encountered: