From 4f1037f86a6291c6cd51abdaf29b83e077a49a58 Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Mon, 13 Feb 2023 14:22:02 -0800 Subject: [PATCH] [flang][build] Fix build issue reported on recent commit 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 | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/flang/lib/Semantics/data-to-inits.cpp b/flang/lib/Semantics/data-to-inits.cpp index d91a250..52191ed 100644 --- a/flang/lib/Semantics/data-to-inits.cpp +++ b/flang/lib/Semantics/data-to-inits.cpp @@ -436,26 +436,25 @@ bool DataInitializationCompiler::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( -- 2.7.4