-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix MSVC Warning when compiling format.cpp #2078
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This pull request was exported from Phabricator. Differential Revision: D50122319 |
NickGerleman
added a commit
to NickGerleman/react-native-windows
that referenced
this pull request
Oct 11, 2023
**Build flags:** 1. Change compiler flag to build with C++ 20 2. Remove the `/await` flag which was used to enable experimental coroutines TS support in C++ 17 **Coroutines:** 1. Replace coroutine functions with `std::experimental::coroutine_handle` with `std::coroutine_handle` 2. Replace `std::future` usage in coroutines with `concurrency:task` since the former relies on coroutine extensions not part of the C++ 20 standard (provided previously by `/await`) 1. This is recommended by https://learn.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/concurrency#asynchronously-return-a-non-windows-runtime-type **C++ 20 breaking changes** 1. Replace a usage of `allocator.construct()` (deprecated in C++ 17 but silenced in RNW, removed in C++ 20) with placement new. 3. Use `wstring` when passing unicode file paths. `u8string()` is now its own type in C++ 20, that doesn't play nice with libraries not meant to support it, and there isn't a zero-cost way to convert between it and `std::string`. Using wstring APIs for fs path sink lets us avoid that, and ends up avoiding extra conversions/allocations since the path is already UTF-16 internally, and we previously converted to utf8, to convert back to utf16. 4. Interpret some string literal `u8` strings in test data as `char*` using `reinterepret_cast`. This is sadly the portable way to do this, without relying on MSVC setting `/utf-8` (which this project does). 5. Fix "[Explicit template specialization cannot have a storage class](https://stackoverflow.com/questions/29041775/explicit-template-specialization-cannot-have-a-storage-class-member-method-spe)" by moving a function outside of a struct **Folly:** 1. Update folly to take in facebook/folly@abbd46b 3. Set `FOLLY_CFG_NO_COROUTINES` to avoid building Folly coroutine bits, not used by RN (consistent with Android/iOS build) 4. Made facebook/folly#2078 to fix a warning explicitly set by `/sdl` in folly 5. Suppressed C4244 which showed in some Folly concurrency bits. This is already suppressed in other places, but the alternative would be to make an upstream PR or fork 6. Updated the forked files in `TEMP_UntilFollyUpdate` This change should not require updates to any of the consumers of Microsoft.ReactNative. Some care might need to be taken for Office/Win32 build with Folly at the ABI boundary in order to be sure we avoid any ODR violations (though, we're likely to be fine).
NickGerleman
added a commit
to NickGerleman/react-native-windows
that referenced
this pull request
Oct 11, 2023
**Build flags:** 1. Change compiler flag to build with C++ 20 2. Remove the `/await` flag which was used to enable experimental coroutines TS support in C++ 17 **Coroutines:** 1. Replace coroutine functions with `std::experimental::coroutine_handle` with `std::coroutine_handle` 2. Replace `std::future` usage in coroutines with `concurrency:task` since the former relies on coroutine extensions not part of the C++ 20 standard (provided previously by `/await`) 1. This is recommended by https://learn.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/concurrency#asynchronously-return-a-non-windows-runtime-type **C++ 20 breaking changes** 1. Replace a usage of `allocator.construct()` (deprecated in C++ 17 but silenced in RNW, removed in C++ 20) with placement new. 3. Use `wstring` when passing unicode file paths. `u8string()` is now its own type in C++ 20, that doesn't play nice with libraries not meant to support it, and there isn't a zero-cost way to convert between it and `std::string`. Using wstring APIs for fs path sink lets us avoid that, and ends up avoiding extra conversions/allocations since the path is already UTF-16 internally, and we previously converted to utf8, to convert back to utf16. 4. Interpret some string literal `u8` strings in test data as `char*` using `reinterepret_cast`. This is sadly the portable way to do this, without relying on MSVC setting `/utf-8` (which this project does). 5. Fix "[Explicit template specialization cannot have a storage class](https://stackoverflow.com/questions/29041775/explicit-template-specialization-cannot-have-a-storage-class-member-method-spe)" by moving a function outside of a struct **Folly:** 1. Update folly to take in facebook/folly@abbd46b 3. Set `FOLLY_CFG_NO_COROUTINES` to avoid building Folly coroutine bits, not used by RN (consistent with Android/iOS build) 4. Made facebook/folly#2078 to fix a warning explicitly set by `/sdl` in folly 5. Suppressed C4244 which showed in some Folly concurrency bits. This is already suppressed in other places, but the alternative would be to make an upstream PR or fork 6. Updated the forked files in `TEMP_UntilFollyUpdate` This change should not require updates to any of the consumers of Microsoft.ReactNative. Some care might need to be taken for Office/Win32 build with Folly at the ABI boundary in order to be sure we avoid any ODR violations (though, we're likely to be fine).
…acebook#2078) Summary: MSVC fires [C4146](https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4146) "unary minus operator applied to unsigned type, result still unsigned" when compiling `format.cpp`, through calling `constexpr_pow` on an unsigned type, which then calls into `contexpr_trunc`. The compiler doesn't know negation will never happen for unsigned types, so this instead adds a specialization for integral types of the function that just no-ops. Reviewed By: Gownta Differential Revision: D50122319
This pull request was exported from Phabricator. Differential Revision: D50122319 |
1 similar comment
This pull request was exported from Phabricator. Differential Revision: D50122319 |
NickGerleman
force-pushed
the
export-D50122319
branch
from
October 11, 2023 21:36
2ef0df1
to
ff07913
Compare
This pull request has been merged in 30be342. |
facebook-github-bot
pushed a commit
to facebook/hhvm
that referenced
this pull request
Oct 23, 2023
Summary: X-link: facebook/folly#2078 MSVC fires [C4146](https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4146) "unary minus operator applied to unsigned type, result still unsigned" when compiling `format.cpp`, through calling `constexpr_pow` on an unsigned type, which then calls into `contexpr_trunc`. The compiler doesn't know negation will never happen for unsigned types, so this instead adds a specialization for integral types of the function that just no-ops. Differential Revision: D50122319 fbshipit-source-id: f66f09a5de4dec1a7f32486cbc532d7953302b05
NickGerleman
added a commit
to NickGerleman/react-native-windows
that referenced
this pull request
Nov 1, 2023
**Build flags:** 1. Change compiler flag to build with C++ 20 2. Remove the `/await` flag which was used to enable experimental coroutines TS support in C++ 17 **Coroutines:** 1. Replace coroutine functions with `std::experimental::coroutine_handle` with `std::coroutine_handle` 2. Replace `std::future` usage in coroutines with `concurrency:task` since the former relies on coroutine extensions not part of the C++ 20 standard (provided previously by `/await`) 1. This is recommended by https://learn.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/concurrency#asynchronously-return-a-non-windows-runtime-type **C++ 20 breaking changes** 1. Replace a usage of `allocator.construct()` (deprecated in C++ 17 but silenced in RNW, removed in C++ 20) with placement new. 3. Use `wstring` when passing unicode file paths. `u8string()` is now its own type in C++ 20, that doesn't play nice with libraries not meant to support it, and there isn't a zero-cost way to convert between it and `std::string`. Using wstring APIs for fs path sink lets us avoid that, and ends up avoiding extra conversions/allocations since the path is already UTF-16 internally, and we previously converted to utf8, to convert back to utf16. 4. Interpret some string literal `u8` strings in test data as `char*` using `reinterepret_cast`. This is sadly the portable way to do this, without relying on MSVC setting `/utf-8` (which this project does). 5. Fix "[Explicit template specialization cannot have a storage class](https://stackoverflow.com/questions/29041775/explicit-template-specialization-cannot-have-a-storage-class-member-method-spe)" by moving a function outside of a struct **Folly:** 1. Update folly to take in facebook/folly@abbd46b 3. Set `FOLLY_CFG_NO_COROUTINES` to avoid building Folly coroutine bits, not used by RN (consistent with Android/iOS build) 4. Made facebook/folly#2078 to fix a warning explicitly set by `/sdl` in folly 5. Suppressed C4244 which showed in some Folly concurrency bits. This is already suppressed in other places, but the alternative would be to make an upstream PR or fork 6. Updated the forked files in `TEMP_UntilFollyUpdate` This change should not require updates to any of the consumers of Microsoft.ReactNative. Some care might need to be taken for Office/Win32 build with Folly at the ABI boundary in order to be sure we avoid any ODR violations (though, we're likely to be fine).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
MSVC fires C4146 "unary minus operator applied to unsigned type, result still unsigned" when compiling
format.cpp
, through callingconstexpr_pow
on an unsigned type, which then calls intocontexpr_trunc
.The compiler doesn't know negation will never happen for unsigned types, so this instead adds a specialization for integral types of the function that just no-ops.
Differential Revision: D50122319