-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[flang] Fix -Wcharacter-conversion warnings (NFC) #155873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-flang-parser @llvm/pr-subscribers-flang-semantics Author: Nikita Popov (nikic) ChangesThis fixes new warnings when building with Clang 21, encountered in #155627. Full diff: https://github.com/llvm/llvm-project/pull/155873.diff 2 Files Affected:
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;
|
@@ -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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is safe due to the preceding check.
@@ -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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one looks like it might truncate. Don't know whether this is somehow excluded by the broader context.
This fixes new warnings when building with Clang 21, encountered in #155627.