From e5549fb18cf69971895a79eb82e2835fbe51d812 Mon Sep 17 00:00:00 2001 From: Anton Bachin Date: Tue, 7 Aug 2018 16:00:36 -0500 Subject: [PATCH] Docs: add notes about enabling C4062 on msvc Resolves #49. [skip ci] --- README.md | 33 ++++++++++++++++++--------------- doc/tutorial/4-switch.md | 4 ++++ example/4-switch.cc | 2 ++ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index be1a51d..054efb9 100644 --- a/README.md +++ b/README.md @@ -61,37 +61,40 @@ Simply add `enum.h` to your project. ## Limitations -The biggest limitation is that the `BETTER_ENUM` macro can't be used inside a +1. The biggest limitation is that the `BETTER_ENUM` macro can't be used inside a class. This seems [difficult to remove][nested]. There is a workaround with `typedef` (or C++11 `using`): -``` -BETTER_ENUM(SomePrefix_Color, uint8_t, Red, Green, Blue) + ``` + BETTER_ENUM(SomePrefix_Color, uint8_t, Red, Green, Blue) -struct triplet { - typedef SomePrefix_Color Color; - Color r, g, b; -}; + struct triplet { + typedef SomePrefix_Color Color; + Color r, g, b; + }; -triplet::Color color; -``` + triplet::Color color; + ``` -You can, however, use `BETTER_ENUM` inside a namespace. + You can, however, use `BETTER_ENUM` inside a namespace. -The macro has a soft limit of 64 declared constants. You can extend it by +2. The macro has a soft limit of 64 declared constants. You can extend it by following [these instructions][extend]. Ultimately, the number of constants is limited by your compiler's maximum macro argument count. -In some cases, it is necessary to prefix constants such as `Channel::Red` with a +3. In some cases, it is necessary to prefix constants such as `Channel::Red` with a `+` to explicitly promote them to type `Channel`. For example, if you are doing a comparison: -``` -channel == +Channel::Red -``` + ``` + channel == +Channel::Red + ``` + +4. On msvc, you may need to enable [warning C4062][C4062] to get `switch` case exhaustiveness checking. [nested]: http://aantron.github.io/better-enums/DesignDecisionsFAQ.html#NoEnumInsideClass [extend]: http://aantron.github.io/better-enums/ExtendingLimits.html +[C4062]: https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4062
diff --git a/doc/tutorial/4-switch.md b/doc/tutorial/4-switch.md index 3b87f47..607a792 100644 --- a/doc/tutorial/4-switch.md +++ b/doc/tutorial/4-switch.md @@ -21,6 +21,10 @@ A Better Enum can be used directly in a `switch` statement: If you miss a case or add a redundant one, your compiler should be able to give you a warning — try it! +Note that on msvc, you may need to enable [warning C4062][C4062]. + +[C4062]: https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4062 + --- std::cout << n << std::endl; diff --git a/example/4-switch.cc b/example/4-switch.cc index 8adb7b3..31687d7 100644 --- a/example/4-switch.cc +++ b/example/4-switch.cc @@ -22,6 +22,8 @@ int main() // If you miss a case or add a redundant one, your compiler should be able to // give you a warning - try it! +// +// Note that on msvc, you may need to enable warning C4062. std::cout << n << std::endl;