From dee4686227842aa0e8380c7925049a5df9c4f781 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Wed, 16 Sep 2020 14:58:29 -0500 Subject: [PATCH] [flang][msvc] Work around if constexpr (false) evaluation. NFC. MSVC tries to expand templates that are in the false-branch of a `if constexpr` construct. In this case, the condition checks whether a tuple has at least one element and then is trying to access it using `std::get<0>`, which fails when the tuple has 0 elements. The workaround is to extract that case into a separate method. This patch is part of the series to make flang compilable with MS Visual Studio . Reviewed By: klausler Differential Revision: https://reviews.llvm.org/D87728 --- flang/lib/Parser/basic-parsers.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/flang/lib/Parser/basic-parsers.h b/flang/lib/Parser/basic-parsers.h index 56d9ff1..c92ece0 100644 --- a/flang/lib/Parser/basic-parsers.h +++ b/flang/lib/Parser/basic-parsers.h @@ -729,13 +729,7 @@ public: return RESULT{}; } else { if constexpr (sizeof...(PARSER) == 1) { - if constexpr (std::is_same_v) { - if (std::get<0>(parsers_).Parse(state)) { - return RESULT{}; - } - } else if (auto arg{std::get<0>(parsers_).Parse(state)}) { - return RESULT{std::move(*arg)}; - } + return ParseOne(state); } else { ApplyArgs results; using Sequence = std::index_sequence_for; @@ -749,6 +743,17 @@ public: } private: + std::optional ParseOne(ParseState &state) const { + if constexpr (std::is_same_v) { + if (std::get<0>(parsers_).Parse(state)) { + return RESULT{}; + } + } else if (auto arg{std::get<0>(parsers_).Parse(state)}) { + return RESULT{std::move(*arg)}; + } + return std::nullopt; + } + const std::tuple parsers_; }; -- 2.7.4