summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorasynts <asynts@gmail.com>2020-09-22 13:42:30 +0200
committerAndreas Kling <kling@serenityos.org>2020-09-22 15:06:40 +0200
commit90536a15581a95e70c351de7d50ac1d20a2fe2ce (patch)
treeeaca84c33b4c9222c693ab857c580ea28b8794ba /AK
parente5497a326aed3a869593242ceb467d8718a72e8c (diff)
downloadserenity-90536a15581a95e70c351de7d50ac1d20a2fe2ce.zip
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.
Diffstat (limited to 'AK')
-rw-r--r--AK/Format.cpp21
-rw-r--r--AK/NeverDestroyed.h2
-rw-r--r--AK/StdLibExtras.h16
-rw-r--r--AK/Tests/TestFormat.cpp2
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<T, typename EnableIf<IsIntegral<T>::value>::Type>::format(StringB
template struct Formatter<StringView>;
template struct Formatter<String>;
-template struct Formatter<u8, void>;
-template struct Formatter<u16, void>;
-template struct Formatter<u32, void>;
-template struct Formatter<u64, void>;
-template struct Formatter<i8, void>;
-template struct Formatter<i16, void>;
-template struct Formatter<i32, void>;
-template struct Formatter<i64, void>;
+template struct Formatter<unsigned char, void>;
+template struct Formatter<unsigned short, void>;
+template struct Formatter<unsigned int, void>;
+template struct Formatter<unsigned long, void>;
+template struct Formatter<unsigned long long, void>;
+template struct Formatter<char, void>;
+template struct Formatter<short, void>;
+template struct Formatter<int, void>;
+template struct Formatter<long, void>;
+template struct Formatter<long long, void>;
+
+// C++ is weird.
+template struct Formatter<signed char, void>;
} // 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 <AK/Noncopyable.h>
-#include <AK/StdLibExtras.h>
+#include <AK/Types.h>
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<typename T>
struct __IsIntegral : FalseType {
};
template<>
-struct __IsIntegral<u8> : TrueType {
+struct __IsIntegral<unsigned char> : TrueType {
+};
+template<>
+struct __IsIntegral<unsigned short> : TrueType {
};
template<>
-struct __IsIntegral<u16> : TrueType {
+struct __IsIntegral<unsigned int> : TrueType {
};
template<>
-struct __IsIntegral<u32> : TrueType {
+struct __IsIntegral<unsigned long> : TrueType {
};
template<>
-struct __IsIntegral<u64> : TrueType {
+struct __IsIntegral<unsigned long long> : TrueType {
};
template<typename T>
using IsIntegral = __IsIntegral<typename MakeUnsigned<typename RemoveCV<T>::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)