[flang-commits] [flang] dee4686 - [flang][msvc] Work around if constexpr (false) evaluation. NFC.
Michael Kruse via flang-commits
flang-commits at lists.llvm.org
Wed Sep 16 13:01:47 PDT 2020
Author: Michael Kruse
Date: 2020-09-16T15:01:39-05:00
New Revision: dee4686227842aa0e8380c7925049a5df9c4f781
URL: https://github.com/llvm/llvm-project/commit/dee4686227842aa0e8380c7925049a5df9c4f781
DIFF: https://github.com/llvm/llvm-project/commit/dee4686227842aa0e8380c7925049a5df9c4f781.diff
LOG: [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 <http://lists.llvm.org/pipermail/flang-dev/2020-July/000448.html>.
Reviewed By: klausler
Differential Revision: https://reviews.llvm.org/D87728
Added:
Modified:
flang/lib/Parser/basic-parsers.h
Removed:
################################################################################
diff --git a/flang/lib/Parser/basic-parsers.h b/flang/lib/Parser/basic-parsers.h
index 56d9ff1b0706..c92ece0ef677 100644
--- a/flang/lib/Parser/basic-parsers.h
+++ b/flang/lib/Parser/basic-parsers.h
@@ -729,13 +729,7 @@ template <typename RESULT, typename... PARSER> class ApplyConstructor {
return RESULT{};
} else {
if constexpr (sizeof...(PARSER) == 1) {
- if constexpr (std::is_same_v<Success, typename PARSER::resultType...>) {
- 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<PARSER...> results;
using Sequence = std::index_sequence_for<PARSER...>;
@@ -749,6 +743,17 @@ template <typename RESULT, typename... PARSER> class ApplyConstructor {
}
private:
+ std::optional<resultType> ParseOne(ParseState &state) const {
+ if constexpr (std::is_same_v<Success, typename PARSER::resultType...>) {
+ 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<PARSER...> parsers_;
};
More information about the flang-commits
mailing list