Import C++ Standard Template Library

You can now use the hardest fastest and most dangerous language there is
with Cosmopolitan. So far about 75% of LLVM libcxx has been added. A few
breaking changes needed to be made to help this go smoothly.

- Rename nothrow to dontthrow
- Rename nodiscard to dontdiscard
- Add some libm functions, e.g. lgamma, nan, etc.
- Change intmax_t from int128 to int64 like everything else
- Introduce %jjd formatting directive for int128_t
- Introduce strtoi128(), strtou128(), etc.
- Rename bsrmax() to bsr128()

Some of the templates that should be working currently are std::vector,
std::string, std::map, std::set, std::deque, etc.
This commit is contained in:
Justine Tunney 2022-03-22 05:51:41 -07:00
parent 5022f9e920
commit 868af3f950
286 changed files with 123987 additions and 507 deletions

View file

@ -306,24 +306,24 @@ TEST(strtoimax, testEndPtr) {
ASSERT_EQ(1, e - p);
}
TEST(strtoimax, testLimits) {
TEST(strtoi128, testLimits) {
EXPECT_EQ(
((uintmax_t)0xffffffffffffffff) << 64 | (uintmax_t)0xffffffffffffffff,
strtoimax("-1", NULL, 0));
((uint128_t)0xffffffffffffffff) << 64 | (uint128_t)0xffffffffffffffff,
strtoi128("-1", NULL, 0));
EXPECT_EQ(
((uintmax_t)0x7fffffffffffffff) << 64 | (uintmax_t)0xffffffffffffffff,
strtoimax("0x7fffffffffffffffffffffffffffffff", NULL, 0));
((uint128_t)0x7fffffffffffffff) << 64 | (uint128_t)0xffffffffffffffff,
strtoi128("0x7fffffffffffffffffffffffffffffff", NULL, 0));
}
TEST(strtoimax, testOutsideLimit) {
TEST(strtoi128, testOutsideLimit) {
errno = 0;
EXPECT_EQ(
((uintmax_t)0x7fffffffffffffff) << 64 | (uintmax_t)0xffffffffffffffff,
strtoimax("0x80000000000000000000000000000000", NULL, 0));
((uint128_t)0x7fffffffffffffff) << 64 | (uint128_t)0xffffffffffffffff,
strtoi128("0x80000000000000000000000000000000", NULL, 0));
EXPECT_EQ(ERANGE, errno);
errno = 0;
EXPECT_EQ(((uintmax_t)0x8000000000000000) << 64 | 0x0000000000000000,
strtoimax("-0x80000000000000000000000000000001", NULL, 0));
EXPECT_EQ(((uint128_t)0x8000000000000000) << 64 | 0x0000000000000000,
strtoi128("-0x80000000000000000000000000000001", NULL, 0));
EXPECT_EQ(ERANGE, errno);
}
@ -335,6 +335,7 @@ TEST(strtoul, neghex) {
TEST(strtoumax, testZero) {
EXPECT_EQ(UINTMAX_MIN, strtoumax("0", NULL, 0));
EXPECT_EQ(UINT128_MIN, strtou128("0", NULL, 0));
}
TEST(strtoumax, testDecimal) {
EXPECT_EQ(123, strtoumax("123", NULL, 0));
@ -353,16 +354,16 @@ TEST(strtoumax, testBinary) {
EXPECT_EQ(42, strtoumax("0b101010", NULL, 2));
}
TEST(strtoumax, testMaximum) {
EXPECT_EQ(UINTMAX_MAX,
strtoumax("340282366920938463463374607431768211455", NULL, 0));
EXPECT_EQ(UINTMAX_MAX,
strtoumax("0xffffffffffffffffffffffffffffffff", NULL, 0));
TEST(strtou128, test128imum) {
EXPECT_EQ(UINT128_MAX,
strtou128("340282366920938463463374607431768211455", NULL, 0));
EXPECT_EQ(UINT128_MAX,
strtou128("0xffffffffffffffffffffffffffffffff", NULL, 0));
}
TEST(strtoumax, testTwosBane) {
EXPECT_EQ(((uintmax_t)0x8000000000000000) << 64 | 0x0000000000000000,
strtoumax("0x80000000000000000000000000000000", NULL, 0));
TEST(strtou128, testTwosBane) {
EXPECT_EQ(((uint128_t)0x8000000000000000) << 64 | 0x0000000000000000,
strtou128("0x80000000000000000000000000000000", NULL, 0));
}
TEST(wcstol, test) {
@ -566,4 +567,12 @@ BENCH(atoi, bench) {
EXPROPRIATE(wcstoimax(VEIL("r", L"100000000"), 0, 10)));
EZBENCH2("wcstoumax 10⁸", donothing,
EXPROPRIATE(wcstoimax(VEIL("r", L"100000000"), 0, 10)));
EZBENCH2("strtoi128 10⁸", donothing,
EXPROPRIATE(strtoi128(VEIL("r", "100000000"), 0, 10)));
EZBENCH2("strtou128 10⁸", donothing,
EXPROPRIATE(strtoi128(VEIL("r", "100000000"), 0, 10)));
EZBENCH2("wcstoi128 10⁸", donothing,
EXPROPRIATE(wcstoi128(VEIL("r", L"100000000"), 0, 10)));
EZBENCH2("wcstou128 10⁸", donothing,
EXPROPRIATE(wcstoi128(VEIL("r", L"100000000"), 0, 10)));
}