Commit 62970df6 authored by Dan Melnic's avatar Dan Melnic Committed by Facebook GitHub Bot

Fix CPP20 compile issues

Summary: Fix CPP20 compile issues

Reviewed By: yfeldblum

Differential Revision: D32010566

fbshipit-source-id: 203a272c80a0d54ac7a65809feed146ae0ee70f8
parent eb15eadc
......@@ -1198,7 +1198,7 @@ const_dynamic_view::descend_unchecked_(Key const& key) const noexcept {
if /* constexpr */ (!std::is_integral<Key>::value) {
return nullptr;
}
if (key < 0 || key >= parray->size()) {
if (key < 0 || folly::to_unsigned(key) >= parray->size()) {
return nullptr;
}
return &(*parray)[size_t(key)];
......
......@@ -29,15 +29,20 @@ using folly::json::parse_error;
using folly::json::print_error;
TEST(Json, Unicode) {
auto val = parseJson(u8"\"I \u2665 UTF-8\"");
EXPECT_EQ(u8"I \u2665 UTF-8", val.asString());
auto val = parseJson(reinterpret_cast<const char*>(u8"\"I \u2665 UTF-8\""));
EXPECT_EQ(reinterpret_cast<const char*>(u8"I \u2665 UTF-8"), val.asString());
val = parseJson("\"I \\u2665 UTF-8\"");
EXPECT_EQ(u8"I \u2665 UTF-8", val.asString());
val = parseJson(u8"\"I \U0001D11E playing in G-clef\"");
EXPECT_EQ(u8"I \U0001D11E playing in G-clef", val.asString());
EXPECT_EQ(reinterpret_cast<const char*>(u8"I \u2665 UTF-8"), val.asString());
val = parseJson(
reinterpret_cast<const char*>(u8"\"I \U0001D11E playing in G-clef\""));
EXPECT_EQ(
reinterpret_cast<const char*>(u8"I \U0001D11E playing in G-clef"),
val.asString());
val = parseJson("\"I \\uD834\\uDD1E playing in G-clef\"");
EXPECT_EQ(u8"I \U0001D11E playing in G-clef", val.asString());
EXPECT_EQ(
reinterpret_cast<const char*>(u8"I \U0001D11E playing in G-clef"),
val.asString());
}
TEST(Json, Parse) {
......@@ -568,7 +573,7 @@ TEST(Json, JsonNonAsciiEncoding) {
TEST(Json, UTF8Retention) {
// test retention with valid utf8 strings
std::string input = u8"\u2665";
std::string input = reinterpret_cast<const char*>(u8"\u2665");
std::string jsonInput = folly::toJson(input);
std::string output = folly::parseJson(jsonInput).asString();
std::string jsonOutput = folly::toJson(output);
......@@ -587,7 +592,7 @@ TEST(Json, UTF8EncodeNonAsciiRetention) {
opts.encode_non_ascii = true;
// test encode_non_ascii valid utf8 strings
std::string input = u8"\u2665";
std::string input = reinterpret_cast<const char*>(u8"\u2665");
std::string jsonInput = folly::json::serialize(input, opts);
std::string output = folly::parseJson(jsonInput).asString();
std::string jsonOutput = folly::json::serialize(output, opts);
......@@ -623,19 +628,20 @@ TEST(Json, UTF8Validation) {
opts.skip_invalid_utf8 = true;
EXPECT_EQ(
folly::json::serialize("a\xe0\xa0\x80z\xc0\x80", opts),
u8"\"a\xe0\xa0\x80z\ufffd\ufffd\"");
reinterpret_cast<const char*>(u8"\"a\xe0\xa0\x80z\ufffd\ufffd\""));
EXPECT_EQ(
folly::json::serialize("a\xe0\xa0\x80z\xc0\x80\x80", opts),
u8"\"a\xe0\xa0\x80z\ufffd\ufffd\ufffd\"");
reinterpret_cast<const char*>(u8"\"a\xe0\xa0\x80z\ufffd\ufffd\ufffd\""));
EXPECT_EQ(
folly::json::serialize("z\xc0\x80z\xe0\xa0\x80", opts),
u8"\"z\ufffd\ufffdz\xe0\xa0\x80\"");
reinterpret_cast<const char*>(u8"\"z\ufffd\ufffdz\xe0\xa0\x80\""));
EXPECT_EQ(
folly::json::serialize("\xF6\x8D\x9B\xBC", opts),
u8"\"\ufffd\ufffd\ufffd\ufffd\"");
reinterpret_cast<const char*>(u8"\"\ufffd\ufffd\ufffd\ufffd\""));
EXPECT_EQ(
folly::json::serialize("invalid\xF6\x8D\x9B\xBCinbetween", opts),
u8"\"invalid\ufffd\ufffd\ufffd\ufffdinbetween\"");
reinterpret_cast<const char*>(
u8"\"invalid\ufffd\ufffd\ufffd\ufffdinbetween\""));
opts.encode_non_ascii = true;
EXPECT_EQ(
......
......@@ -1424,6 +1424,8 @@ TEST(Range, LiteralSuffix) {
constexpr auto literalPiece = "hello"_sp;
constexpr StringPiece piece = "hello";
EXPECT_EQ(literalPiece, piece);
#if __cplusplus <= 202001L
constexpr auto literalPiece8 = u8"hello"_sp;
#if __cpp_char8_t >= 201811L
constexpr Range<char8_t const*> piece8 = u8"hello";
......@@ -1431,6 +1433,8 @@ TEST(Range, LiteralSuffix) {
constexpr Range<char const*> piece8 = u8"hello";
#endif
EXPECT_EQ(literalPiece8, piece8);
#endif
constexpr auto literalPiece16 = u"hello"_sp;
constexpr Range<char16_t const*> piece16{u"hello", 5};
EXPECT_EQ(literalPiece16, piece16);
......
......@@ -428,9 +428,10 @@ TEST(Try, ValueOverloads) {
{
auto obj = Try<int>{make_exception_wrapper<std::range_error>("oops")};
EXPECT_THROW(obj.value(), std::range_error);
EXPECT_THROW(std::move(obj.value()), std::range_error);
EXPECT_THROW(as_const(obj.value()), std::range_error);
EXPECT_THROW(std::move(as_const(obj.value())), std::range_error);
EXPECT_THROW(std::ignore = std::move(obj.value()), std::range_error);
EXPECT_THROW(std::ignore = as_const(obj.value()), std::range_error);
EXPECT_THROW(
std::ignore = std::move(as_const(obj.value())), std::range_error);
}
}
......
......@@ -23,7 +23,8 @@
using namespace folly;
using namespace std;
const folly::StringPiece kTestUTF8 = u8"This is \U0001F602 stuff!";
const folly::StringPiece kTestUTF8 =
reinterpret_cast<const char*>(u8"This is \U0001F602 stuff!");
TEST(UTF8StringPiece, valid_utf8) {
folly::StringPiece sp = kTestUTF8;
......@@ -47,7 +48,8 @@ TEST(UTF8StringPiece, invalid_mid_codepoint) {
}
TEST(UTF8StringPiece, valid_implicit_conversion) {
std::string input = u8"\U0001F602\U0001F602\U0001F602";
std::string input =
reinterpret_cast<const char*>(u8"\U0001F602\U0001F602\U0001F602");
auto checkImplicitCtor = [](UTF8StringPiece implicitCtor) {
return implicitCtor.walk_size();
};
......
......@@ -647,11 +647,15 @@ map<void*, int> AllocTracker::Owner;
template <class T>
struct Alloc : AllocTracker, Ticker {
typedef typename std::allocator<T>::pointer pointer;
typedef typename std::allocator<T>::const_pointer const_pointer;
typedef typename std::allocator<T>::difference_type difference_type;
typedef typename std::allocator<T>::size_type size_type;
typedef typename std::allocator<T>::value_type value_type;
typedef typename std::allocator_traits<std::allocator<T>>::pointer pointer;
typedef typename std::allocator_traits<std::allocator<T>>::const_pointer
const_pointer;
typedef typename std::allocator_traits<std::allocator<T>>::difference_type
difference_type;
typedef
typename std::allocator_traits<std::allocator<T>>::size_type size_type;
typedef
typename std::allocator_traits<std::allocator<T>>::value_type value_type;
//-----
// impl
......@@ -710,14 +714,15 @@ struct Alloc : AllocTracker, Ticker {
template <class U, class... Args>
void construct(U* p, Args&&... args) {
Tick("construct");
a.construct(p, std::forward<Args>(args)...);
std::allocator_traits<std::allocator<T>>::construct(
a, p, std::forward<Args>(args)...);
Constructed++;
}
template <class U>
void destroy(U* p) {
Destroyed++;
a.destroy(p);
std::allocator_traits<std::allocator<T>>::destroy(a, p);
}
//--------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment