[flang] Recode a switch() to dodge a sketchy warning
authorpeter klausler <pklausler@nvidia.com>
Fri, 18 Jun 2021 23:55:37 +0000 (16:55 -0700)
committerpeter klausler <pklausler@nvidia.com>
Fri, 18 Jun 2021 23:58:44 +0000 (16:58 -0700)
One of the buildbots uses a compiler (can't tell which) that
doesn't approve of a "default:" in a switch statement whose
cases appear to completely cover all possible values of an
enum class.  But this switch is in raw data dumping code that
needs to allow for incorrect values in memory.  So rewrite it
as a cascade of if statements; performance doesn't matter here.

flang/runtime/type-info.cpp

index ef3c472..df72fc4 100644 (file)
@@ -158,22 +158,16 @@ FILE *Component::Dump(FILE *f) const {
   std::fprintf(f, "Component @ 0x%p:\n", reinterpret_cast<const void *>(this));
   std::fputs("    name: ", f);
   DumpScalarCharacter(f, name(), "Component::name");
-  switch (genre_) {
-  case Genre::Data:
+  if (genre_ == Genre::Data) {
     std::fputs("    Data       ", f);
-    break;
-  case Genre::Pointer:
+  } else if (genre_ == Genre::Pointer) {
     std::fputs("    Pointer    ", f);
-    break;
-  case Genre::Allocatable:
+  } else if (genre_ == Genre::Allocatable) {
     std::fputs("    Allocatable", f);
-    break;
-  case Genre::Automatic:
+  } else if (genre_ == Genre::Automatic) {
     std::fputs("    Automatic  ", f);
-    break;
-  default:
+  } else {
     std::fprintf(f, "    (bad genre 0x%x)", static_cast<int>(genre_));
-    break;
   }
   std::fprintf(f, " category %d  kind %d  rank %d  offset 0x%zx\n", category_,
       kind_, rank_, static_cast<std::size_t>(offset_));