[flang][build] Fix build issue reported on recent commit
authorPeter Klausler <pklausler@nvidia.com>
Mon, 13 Feb 2023 22:22:02 +0000 (14:22 -0800)
committerPeter Klausler <pklausler@nvidia.com>
Mon, 13 Feb 2023 22:24:18 +0000 (14:24 -0800)
Some compiler (not specified) reported to issue an error on a
"default:" clause in a switch statement whose cases cover all of
the values of an "enum class".  Since other compilers/versions
are known to complain in the other direction, change the switch
statement to a cascade of ifs.

flang/lib/Semantics/data-to-inits.cpp

index d91a250..52191ed 100644 (file)
@@ -436,26 +436,25 @@ bool DataInitializationCompiler<DSV>::InitElement(
             DescribeElement(), designatorType->AsFortran());
       }
       auto folded{evaluate::Fold(context, std::move(converted->first))};
-      switch (GetImage().Add(
-          offsetSymbol.offset(), offsetSymbol.size(), folded, context)) {
-      case evaluate::InitialImage::Ok:
+      // Rewritten from a switch() in order to avoid getting complaints
+      // about a missing "default:" from some compilers and complaints
+      // about a redundant "default:" from others.
+      auto status{GetImage().Add(
+          offsetSymbol.offset(), offsetSymbol.size(), folded, context)};
+      if (status == evaluate::InitialImage::Ok) {
         return true;
-      case evaluate::InitialImage::NotAConstant:
+      } else if (status == evaluate::InitialImage::NotAConstant) {
         exprAnalyzer_.Say(
             "DATA statement value '%s' for '%s' is not a constant"_err_en_US,
             folded.AsFortran(), DescribeElement());
-        break;
-      case evaluate::InitialImage::OutOfRange:
+      } else if (status == evaluate::InitialImage::OutOfRange) {
         OutOfRangeError();
-        break;
-      case evaluate::InitialImage::SizeMismatch:
+      } else if (status == evaluate::InitialImage::SizeMismatch) {
         exprAnalyzer_.Say(
             "DATA statement value '%s' for '%s' has the wrong length"_warn_en_US,
             folded.AsFortran(), DescribeElement());
-        break;
-      default:
+      } else {
         CHECK(exprAnalyzer_.context().AnyFatalError());
-        break;
       }
     } else {
       exprAnalyzer_.context().Say(