[flang] Fix build warning
authorPeter Klausler <pklausler@nvidia.com>
Wed, 1 Feb 2023 22:05:57 +0000 (14:05 -0800)
committerPeter Klausler <pklausler@nvidia.com>
Wed, 1 Feb 2023 22:08:02 +0000 (14:08 -0800)
It's basically impossible to write a switch statement with a case
for every enumerator in an enum class if the cases each have a
return statement and get it to compile without warnings for all
of our build compilers & versions.  Rewrite as a sequence of
if statements.

flang/lib/Evaluate/check-expression.cpp

index 6cf1f85..12ffdc9 100644 (file)
@@ -494,20 +494,23 @@ static bool IsPermissibleInquiry(const semantics::Symbol &firstSymbol,
     return true;
   }
   // Inquiries on local objects may not access a deferred bound or length.
+  // (This code used to be a switch, but it proved impossible to write it
+  // thus without running afoul of bogus warnings from different C++
+  // compilers.)
+  if (field == DescriptorInquiry::Field::Rank) {
+    return true; // always known
+  }
   const auto *object{lastSymbol.detailsIf<semantics::ObjectEntityDetails>()};
-  switch (field) {
-  case DescriptorInquiry::Field::LowerBound:
-  case DescriptorInquiry::Field::Extent:
-  case DescriptorInquiry::Field::Stride:
+  if (field == DescriptorInquiry::Field::LowerBound ||
+      field == DescriptorInquiry::Field::Extent ||
+      field == DescriptorInquiry::Field::Stride) {
     return object && !object->shape().CanBeDeferredShape();
-  case DescriptorInquiry::Field::Rank:
-    return true; // always known
-  case DescriptorInquiry::Field::Len:
+  }
+  if (field == DescriptorInquiry::Field::Len) {
     return object && object->type() &&
         object->type()->category() == semantics::DeclTypeSpec::Character &&
         !object->type()->characterTypeSpec().length().isDeferred();
   }
-  // TODO: Handle non-deferred LEN type parameters of PDTs
   return false;
 }