From 90536a15581a95e70c351de7d50ac1d20a2fe2ce Mon Sep 17 00:00:00 2001 From: asynts Date: Tue, 22 Sep 2020 13:42:30 +0200 Subject: [PATCH] AK: Consider long and unsigned long as integral types. Two things I hate about C++: 1. 'int', 'signed int' and 'unsigned int' are two distinct types while 'char, 'signed char' and 'unsigned char' are *three* distinct types. This is because 'signed int' is an alias for 'int' but 'signed char' can't be an alias for 'char' because on some weird systems 'char' is unsigned. One might think why not do it the other way around, make 'int' an alias for 'signed int' and 'char' an alias for whatever that is on the platform, or make 'char' signed on all platforms. But who am I to ask? 2. 'unsigned long' and 'unsigned long long' are always different types, even if both are 64 bit numbers. This commit fixes a few bugs that coming from this. See Also: 1b3169f405ac9250b65ee3608e2962f51d2d8e3c. --- AK/Format.cpp | 21 +++++++++++++-------- AK/NeverDestroyed.h | 2 +- AK/StdLibExtras.h | 16 +++++++--------- AK/Tests/TestFormat.cpp | 2 +- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/AK/Format.cpp b/AK/Format.cpp index a4823b8e75..aad9a12dab 100644 --- a/AK/Format.cpp +++ b/AK/Format.cpp @@ -182,13 +182,18 @@ void Formatter::value>::Type>::format(StringB template struct Formatter; template struct Formatter; -template struct Formatter; -template struct Formatter; -template struct Formatter; -template struct Formatter; -template struct Formatter; -template struct Formatter; -template struct Formatter; -template struct Formatter; +template struct Formatter; +template struct Formatter; +template struct Formatter; +template struct Formatter; +template struct Formatter; +template struct Formatter; +template struct Formatter; +template struct Formatter; +template struct Formatter; +template struct Formatter; + +// C++ is weird. +template struct Formatter; } // namespace AK diff --git a/AK/NeverDestroyed.h b/AK/NeverDestroyed.h index 361f519043..64035a759a 100644 --- a/AK/NeverDestroyed.h +++ b/AK/NeverDestroyed.h @@ -27,7 +27,7 @@ #pragma once #include -#include +#include namespace AK { diff --git a/AK/StdLibExtras.h b/AK/StdLibExtras.h index 68a662bd9a..9de44d0963 100644 --- a/AK/StdLibExtras.h +++ b/AK/StdLibExtras.h @@ -26,11 +26,6 @@ #pragma once -typedef __UINT64_TYPE__ u64; -typedef __UINT32_TYPE__ u32; -typedef __UINT16_TYPE__ u16; -typedef __UINT8_TYPE__ u8; - #define UNUSED_PARAM(x) (void)x inline constexpr unsigned round_up_to_power_of_two(unsigned value, unsigned power_of_two) @@ -461,16 +456,19 @@ template struct __IsIntegral : FalseType { }; template<> -struct __IsIntegral : TrueType { +struct __IsIntegral : TrueType { }; template<> -struct __IsIntegral : TrueType { +struct __IsIntegral : TrueType { }; template<> -struct __IsIntegral : TrueType { +struct __IsIntegral : TrueType { }; template<> -struct __IsIntegral : TrueType { +struct __IsIntegral : TrueType { +}; +template<> +struct __IsIntegral : TrueType { }; template using IsIntegral = __IsIntegral::Type>::Type>; diff --git a/AK/Tests/TestFormat.cpp b/AK/Tests/TestFormat.cpp index 90d682e9db..4e4a284ae5 100644 --- a/AK/Tests/TestFormat.cpp +++ b/AK/Tests/TestFormat.cpp @@ -43,7 +43,7 @@ TEST_CASE(format_integers) EXPECT_EQ(AK::format("{}", -17), "-17"); EXPECT_EQ(AK::format("{:04}", 13), "0013"); EXPECT_EQ(AK::format("{:08x}", 4096), "00001000"); - // EXPECT_EQ(AK::format("{}", 0x1111222233334444ull), "1111222233334444"); + EXPECT_EQ(AK::format("{:x}", 0x1111222233334444ull), "1111222233334444"); } TEST_CASE(reorder_format_arguments)