Skip to content

Commit

Permalink
[tools] fix warning on FlagsCategory::ARRAY_SIZE
Browse files Browse the repository at this point in the history
Introducing an extra utility element ARRAY_SIZE into the FlagsCategory
enumeration lead to compilation warning about unhandled enumeration value
in switch statements:

  Building CXX object src/kudu/tools/CMakeFiles/ksck.dir/ksck.cc.o
  ../../src/kudu/tools/ksck.cc: In function ‘const char* kudu::tools::FlagsCategoryToString(kudu::tools::FlagsCategory)’:
  ../../src/kudu/tools/ksck.cc:216:10: warning: enumeration value ‘ARRAY_SIZE’ not handled in switch [-Wswitch]

I think using FlagsCategory::MAX+1 instead of FlagsCategory::ARRAY_SIZE
is better than adding some special handling for ephemeral utility value
in switch statements.

This is a follow-up to a9afbce.

Change-Id: I629373583ecd010ff6e2e2a1362e5977d3ae191e
Reviewed-on: http://gerrit.cloudera.org:8080/15413
Reviewed-by: Andrew Wong <[email protected]>
Tested-by: Kudu Jenkins
  • Loading branch information
alexeyserbin committed Mar 12, 2020
1 parent 2649865 commit b2daddd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/kudu/tools/ksck-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class MockKsckMaster : public KsckMaster {
uuid_ = uuid;
version_ = "mock-version";
if (is_get_flags_available_) {
for (size_t cat = FlagsCategory::MIN; cat < FlagsCategory::ARRAY_SIZE; ++cat) {
for (size_t cat = FlagsCategory::MIN; cat <= FlagsCategory::MAX; ++cat) {
flags_by_category_[cat].flags.emplace();
}
}
Expand Down Expand Up @@ -149,7 +149,7 @@ class MockKsckTabletServer : public KsckTabletServer {
is_get_flags_available_(is_get_flags_available) {
version_ = "mock-version";
if (is_get_flags_available_) {
for (size_t cat = FlagsCategory::MIN; cat < FlagsCategory::ARRAY_SIZE; ++cat) {
for (size_t cat = FlagsCategory::MIN; cat <= FlagsCategory::MAX; ++cat) {
flags_by_category_[cat].flags.emplace();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/kudu/tools/ksck.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ std::ostream& operator<<(std::ostream& lhs, KsckFetchState state) {

const FlagsFetchFilter& GetFlagsCategoryFilter(FlagsCategory category) {
// NOTE: using double braces for std::array aggregate initialization.
static const std::array<FlagsFetchFilter, FlagsCategory::ARRAY_SIZE> kFilters { {
static const std::array<FlagsFetchFilter, FlagsCategory::MAX + 1> kFilters { {
{
// FlagsCategory::TIME_SOURCE
{ "time_source", "builtin_ntp_servers", },
Expand Down
5 changes: 2 additions & 3 deletions src/kudu/tools/ksck.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ enum FlagsCategory {
// Utility members used for range-related expressions.
// NOTE: update the MAX member upon updates
MIN = 0,
MAX = UNUSUAL,
ARRAY_SIZE = MAX + 1,
MAX = UNUSUAL
};

// Information on flags fetched using GetFlags() RPC. Consists of the status of
Expand All @@ -199,7 +198,7 @@ struct FetchedFlags {
};

// Flags retrieved using GetFlags(), indexed by FlagsCategory.
typedef std::array<FetchedFlags, FlagsCategory::ARRAY_SIZE> FetchedFlagsByCategory;
typedef std::array<FetchedFlags, FlagsCategory::MAX + 1> FetchedFlagsByCategory;

// Structure to represent a filter to build appropriate request for GetFlags()
// RPC.
Expand Down

0 comments on commit b2daddd

Please sign in to comment.