aantron / better-enums

C++ compile-time enum to string, iteration, in a single header file
http://aantron.github.io/better-enums
BSD 2-Clause "Simplified" License
1.65k stars 172 forks source link

No Compiler warning for missing case in Switch statement #49

Closed Ar5ham closed 6 years ago

Ar5ham commented 7 years ago

Copy pasting the SafeSwitch example to project created via Visual Studio 2017 and compiling the project, no warning is being produced by the compiler.

Compiler Version:

# From Developer Command Prompt for VS 2017
>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.10.25019

Sample project: BetterEnumTest.zip

aantron commented 7 years ago

That's not good!

I'm not immediately ready to reproduce this, but thanks for including the project. I'll have to look at it after some delay :/

Ar5ham commented 7 years ago

That is fine. Please let me know if you need any more info.

JaapAap commented 6 years ago

For some reason, the warning is off by default, see here. You need to add something like #pragma warning(1 : 4062) to enable it.

aantron commented 6 years ago

It seems that this can only be done by the user, so the code proper of Better Enums doesn't need to be modified.

However, we should probably document enabling this warning, perhaps by adding a short sentence and the link given by @JaapAap, to the tutorial and/or reference.

ikku100 commented 6 years ago

Yes, please document this issue. I spent 15 minutes trying to get this to fail, then I was about to complain about it and apparently it's a known issue! Imho either change the introduction page to mention that it needs enabling for all those people who are sadly on Visual Studio compilers, or remove the mentioning of the feature. Same for the tutorial page on the switch.

Ar5ham commented 6 years ago

Enabling that feature is not always an option either, just FYI. Our project uses shared Libs and public headers and when I enabled the feature I also got warning related to Libs and headers that was not ours to begin with. I have picked up a work item to go take a look at how difficult it would be to fix all of them but I suspect it will be a time consuming effort.

aantron commented 6 years ago

Thanks for pinging. I updated the README and the switch tutorial page with notes about enabling warning C4062 on msvc. I hope that's enough, please let me know/PR if more warnings are needed.

ikku100 commented 6 years ago

That's great, thanks Aantron. It's indeed enough.