forked from couchbaselabs/crouton
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issues using
std::to_chars
on Apple platforms
The float-specialized versions of `std::to_chars` aren't available in libc++ before macOS 13.3 or iOS 16.3, and unfortunately you can't even weak-link to them and check at runtime. So I've switched to a compile-time check against the target's deployment OS version.
- Loading branch information
Showing
6 changed files
with
83 additions
and
51 deletions.
There are no files selected for viewing
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// Availability.hh | ||
// | ||
// | ||
// | ||
|
||
#pragma once | ||
|
||
// Older versions of Apple's libc++ don't have the floating point versions of std::to_chars. | ||
// I used to check at runtime with: | ||
// if (__builtin_available(macOS 13.3, iOS 16.3, tvOS 16.3, watchOS 9.3, *)) { ... } | ||
// Sadly, this doesn't work, because to_chars' availability attributes use the "strict" flag. | ||
// The Clang docs say: | ||
// > The flag strict disallows using API when deploying back to a platform version prior to | ||
// > when the declaration was introduced. An attempt to use such API before its introduction | ||
// > causes a hard error. | ||
#ifdef __APPLE__ | ||
# include <Availability.h> | ||
# include <TargetConditionals.h> | ||
# if (TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED >= 130300) | ||
# define FLOAT_TO_CHARS_AVAILABLE 1 | ||
# elif (TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED >= 160300) | ||
# define FLOAT_TO_CHARS_AVAILABLE 1 | ||
# else | ||
# define FLOAT_TO_CHARS_AVAILABLE 0 | ||
# endif | ||
#else | ||
# define FLOAT_TO_CHARS_AVAILABLE 1 | ||
#endif |
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 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 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