mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
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: 1b3169f405
.
This commit is contained in:
parent
e5497a326a
commit
90536a1558
Notes:
sideshowbarker
2024-07-19 02:17:06 +09:00
Author: https://github.com/asynts Commit: https://github.com/SerenityOS/serenity/commit/90536a15581 Pull-request: https://github.com/SerenityOS/serenity/pull/3580
4 changed files with 22 additions and 19 deletions
|
@ -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
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Noncopyable.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
|
|
|
@ -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<u16> : TrueType {
|
||||
struct __IsIntegral<unsigned short> : TrueType {
|
||||
};
|
||||
template<>
|
||||
struct __IsIntegral<u32> : TrueType {
|
||||
struct __IsIntegral<unsigned int> : TrueType {
|
||||
};
|
||||
template<>
|
||||
struct __IsIntegral<u64> : TrueType {
|
||||
struct __IsIntegral<unsigned long> : TrueType {
|
||||
};
|
||||
template<>
|
||||
struct __IsIntegral<unsigned long long> : TrueType {
|
||||
};
|
||||
template<typename T>
|
||||
using IsIntegral = __IsIntegral<typename MakeUnsigned<typename RemoveCV<T>::Type>::Type>;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue