[flang-commits] [flang] [llvm] [Flang] KIND De-templatization (PR #216960)

Michael Kruse via flang-commits flang-commits at lists.llvm.org
Fri Oct 23 13:48:45 PDT 2026


================
@@ -1950,159 +2008,172 @@ template <typename DERIVED, typename RESULT, typename LEFT, typename RIGHT>
 auto ApplyElementwise(
     FoldingContext &context, Operation<DERIVED, RESULT, LEFT, RIGHT> &operation)
     -> std::optional<Expr<RESULT>> {
+  const int kind{operation.kind()};
   return ApplyElementwise(context, operation,
       std::function<Expr<RESULT>(Expr<LEFT> &&, Expr<RIGHT> &&)>{
-          [](Expr<LEFT> &&left, Expr<RIGHT> &&right) {
-            return Expr<RESULT>{DERIVED{std::move(left), std::move(right)}};
+          [kind](Expr<LEFT> &&left, Expr<RIGHT> &&right) {
+            return Expr<RESULT>{
+                DERIVED{kind, std::move(left), std::move(right)}};
           }});
 }
 
 // Unary operations
 
 template <typename TO, typename FROM>
-common::IfNoLvalue<std::optional<TO>, FROM> ConvertString(FROM &&s) {
-  if constexpr (std::is_same_v<TO, FROM>) {
+common::IfNoLvalue<std::optional<TO>, FROM> ConvertString(
+    int toKind, FROM &&s) {
+  const int fromKind{s.kind()};
+  if (std::is_same_v<TO, FROM> && toKind == fromKind) {
     return std::make_optional<TO>(std::move(s));
+  } else if (auto result{s.ToAscii(toKind)}; !result.IsNull()) {
----------------
Meinersbur wrote:

At some point I must have wanted to make the monostate the error condition, but the error state must be distinct

[`cbea8f6` (this PR)](https://github.com/llvm/llvm-project/pull/216960/changes/cbea8f6213ce475d303e08fc6d5f570e7ac3d333)

https://github.com/llvm/llvm-project/pull/216960


More information about the flang-commits mailing list