[flang-commits] [flang] [flang] Fix -Wcharacter-conversion warnings (NFC) (PR #155873)

via flang-commits flang-commits at lists.llvm.org
Thu Aug 28 09:02:06 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Nikita Popov (nikic)

<details>
<summary>Changes</summary>

This fixes new warnings when building with Clang 21, encountered in https://github.com/llvm/llvm-project/pull/155627.

---
Full diff: https://github.com/llvm/llvm-project/pull/155873.diff


2 Files Affected:

- (modified) flang/lib/Evaluate/fold-implementation.h (+1-1) 
- (modified) flang/lib/Parser/characters.cpp (+2-1) 


``````````diff
diff --git a/flang/lib/Evaluate/fold-implementation.h b/flang/lib/Evaluate/fold-implementation.h
index d757ef6e62eb4..3fdf3a6f38848 100644
--- a/flang/lib/Evaluate/fold-implementation.h
+++ b/flang/lib/Evaluate/fold-implementation.h
@@ -1785,7 +1785,7 @@ common::IfNoLvalue<std::optional<TO>, FROM> ConvertString(FROM &&s) {
       if (static_cast<std::uint64_t>(*iter) > 127) {
         return std::nullopt;
       }
-      str.push_back(*iter);
+      str.push_back(static_cast<typename TO::value_type>(*iter));
     }
     return std::make_optional<TO>(std::move(str));
   }
diff --git a/flang/lib/Parser/characters.cpp b/flang/lib/Parser/characters.cpp
index f6ac777ea874c..1a00b16eefe9d 100644
--- a/flang/lib/Parser/characters.cpp
+++ b/flang/lib/Parser/characters.cpp
@@ -289,7 +289,8 @@ RESULT DecodeString(const std::string &s, bool backslashEscapes) {
         DecodeCharacter<ENCODING>(p, bytes, backslashEscapes)};
     if (decoded.bytes > 0) {
       if (static_cast<std::size_t>(decoded.bytes) <= bytes) {
-        result.append(1, decoded.codepoint);
+        result.append(
+            1, static_cast<typename RESULT::value_type>(decoded.codepoint));
         bytes -= decoded.bytes;
         p += decoded.bytes;
         continue;

``````````

</details>


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


More information about the flang-commits mailing list