googletest
googletest copied to clipboard
Applied C++ Core Guidelines Enum.2 Rule.
Problem: switch statements should cover all cases.
Solution: Added missing enumerations in switch statements and added [[fallthrough]] attribute to denote that the default case is the desired case for these missing enumerations.
Current Functionality: When running the command bazel test --cxxopt='-Wswitch-enum' //..., the following warnings appear:
googlemock/src/gmock-spec-builders.cc:287:11: warning: enumeration value 'kFail' not explicitly handled in switch [-Wswitch-enum]
switch (reaction) {
^
googlemock/src/gmock-spec-builders.cc:287:11: note: add missing switch cases
switch (reaction) {
^
1 warning generated.
INFO: From Compiling googletest/src/gtest.cc:
googletest/src/gtest.cc:3250:11: warning: enumeration value 'kDefault' not explicitly handled in switch [-Wswitch-enum]
switch (color) {
^
googletest/src/gtest.cc:3250:11: note: add missing switch cases
switch (color) {
^
googletest/src/gtest.cc:3501:11: warning: enumeration values 'kNonFatalFailure', 'kFatalFailure', and 'kSkip' not explicitly handled in switch [-Wswitch-enum]
switch (result.type()) {
^
googletest/src/gtest.cc:3501:11: note: add missing switch cases
switch (result.type()) {
^
googletest/src/gtest.cc:3718:11: warning: enumeration values 'kNonFatalFailure', 'kFatalFailure', and 'kSkip' not explicitly handled in switch [-Wswitch-enum]
switch (result.type()) {
^
googletest/src/gtest.cc:3718:11: note: add missing switch cases
switch (result.type()) {
^
3 warnings generated.
Expected Result: When running the command bazel test --cxxopt='-Wswitch-enum' --test_output=errors //..., the user or developer should not expect to see any warnings.
This PR is a follow through of issue 3672
Alternate Solution: I also have a solution where I applied ABSL_FALLTHROUGH_INTENDED; that gets selectively compiled in from an #if flag under GTEST_HAS_ABSL however I could not get this compilation working on my machine.