Skip to content

Commit fabe149

Browse files
authored
fixed #12089 - switched built-in platforms to signed char by default (#8128)
1 parent 81cd36d commit fabe149

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

lib/platform.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ bool Platform::set(Type t)
7373
sizeof_wchar_t = 2;
7474
sizeof_size_t = 4;
7575
sizeof_pointer = 4;
76-
defaultSign = '\0';
76+
defaultSign = 's';
7777
char_bit = 8;
7878
calculateBitMembers();
7979
return true;
@@ -90,7 +90,7 @@ bool Platform::set(Type t)
9090
sizeof_wchar_t = 2;
9191
sizeof_size_t = 8;
9292
sizeof_pointer = 8;
93-
defaultSign = '\0';
93+
defaultSign = 's';
9494
char_bit = 8;
9595
calculateBitMembers();
9696
return true;
@@ -107,7 +107,7 @@ bool Platform::set(Type t)
107107
sizeof_wchar_t = 4;
108108
sizeof_size_t = 4;
109109
sizeof_pointer = 4;
110-
defaultSign = '\0';
110+
defaultSign = 's';
111111
char_bit = 8;
112112
calculateBitMembers();
113113
return true;
@@ -124,7 +124,7 @@ bool Platform::set(Type t)
124124
sizeof_wchar_t = 4;
125125
sizeof_size_t = 8;
126126
sizeof_pointer = 8;
127-
defaultSign = '\0';
127+
defaultSign = 's';
128128
char_bit = 8;
129129
calculateBitMembers();
130130
return true;

releasenotes.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ Changed interface:
1919

2020
Infrastructure & dependencies:
2121
-
22+
23+
Other:
24+
- The built-in "win*" and "unix*" platforms will now default to signed char type instead of unknown signedness. If you require unsigned chars please specify "--funsigned-char"
25+
-

test/testplatform.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class TestPlatform : public TestFixture {
8585
ASSERT_EQUALS(2, platform.sizeof_wchar_t);
8686
ASSERT_EQUALS(4, platform.sizeof_size_t);
8787
ASSERT_EQUALS(4, platform.sizeof_pointer);
88-
ASSERT_EQUALS('\0', platform.defaultSign);
88+
ASSERT_EQUALS('s', platform.defaultSign);
8989
ASSERT_EQUALS(8, platform.char_bit);
9090
ASSERT_EQUALS(16, platform.short_bit);
9191
ASSERT_EQUALS(32, platform.int_bit);
@@ -110,7 +110,7 @@ class TestPlatform : public TestFixture {
110110
ASSERT_EQUALS(4, platform.sizeof_wchar_t);
111111
ASSERT_EQUALS(8, platform.sizeof_size_t);
112112
ASSERT_EQUALS(8, platform.sizeof_pointer);
113-
ASSERT_EQUALS('\0', platform.defaultSign);
113+
ASSERT_EQUALS('s', platform.defaultSign);
114114
ASSERT_EQUALS(8, platform.char_bit);
115115
ASSERT_EQUALS(16, platform.short_bit);
116116
ASSERT_EQUALS(32, platform.int_bit);
@@ -138,7 +138,7 @@ class TestPlatform : public TestFixture {
138138
ASSERT_EQUALS(2, platform.sizeof_wchar_t);
139139
ASSERT_EQUALS(4, platform.sizeof_size_t);
140140
ASSERT_EQUALS(4, platform.sizeof_pointer);
141-
ASSERT_EQUALS('\0', platform.defaultSign);
141+
ASSERT_EQUALS('s', platform.defaultSign);
142142
ASSERT_EQUALS(8, platform.char_bit);
143143
ASSERT_EQUALS(16, platform.short_bit);
144144
ASSERT_EQUALS(32, platform.int_bit);
@@ -166,7 +166,7 @@ class TestPlatform : public TestFixture {
166166
ASSERT_EQUALS(4, platform.sizeof_wchar_t);
167167
ASSERT_EQUALS(4, platform.sizeof_size_t);
168168
ASSERT_EQUALS(4, platform.sizeof_pointer);
169-
ASSERT_EQUALS('\0', platform.defaultSign);
169+
ASSERT_EQUALS('s', platform.defaultSign);
170170
ASSERT_EQUALS(8, platform.char_bit);
171171
ASSERT_EQUALS(16, platform.short_bit);
172172
ASSERT_EQUALS(32, platform.int_bit);
@@ -194,7 +194,7 @@ class TestPlatform : public TestFixture {
194194
ASSERT_EQUALS(2, platform.sizeof_wchar_t);
195195
ASSERT_EQUALS(8, platform.sizeof_size_t);
196196
ASSERT_EQUALS(8, platform.sizeof_pointer);
197-
ASSERT_EQUALS('\0', platform.defaultSign);
197+
ASSERT_EQUALS('s', platform.defaultSign);
198198
ASSERT_EQUALS(8, platform.char_bit);
199199
ASSERT_EQUALS(16, platform.short_bit);
200200
ASSERT_EQUALS(32, platform.int_bit);

test/testtype.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,16 @@ class TestType : public TestFixture {
103103
// unsigned types getting promoted to int sizeof(int) = 4 bytes
104104
// and unsigned types having already a size of 4 bytes
105105
{
106-
const std::string types[] = {"unsigned char", /*[unsigned]*/ "char", "bool", "unsigned short", "unsigned int", "unsigned long"};
106+
const std::string types[] = {"unsigned char", "bool", "unsigned short", "unsigned int", "unsigned long"};
107107
for (const std::string& type : types) {
108108
check(type + " f(" + type +" x) { return x << 31; }", dinit(CheckOptions, $.settings = &settings));
109-
ASSERT_EQUALS("", errout_str());
109+
ASSERT_EQUALS_MSG("", errout_str(), type);
110110
check(type + " f(" + type +" x) { return x << 33; }", dinit(CheckOptions, $.settings = &settings));
111-
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 32-bit value by 33 bits is undefined behaviour\n", errout_str());
111+
ASSERT_EQUALS_MSG("[test.cpp:1]: (error) Shifting 32-bit value by 33 bits is undefined behaviour\n", errout_str(), type);
112112
check(type + " f(int x) { return (x = (" + type + ")x << 32); }", dinit(CheckOptions, $.settings = &settings));
113-
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\n", errout_str());
113+
ASSERT_EQUALS_MSG("[test.cpp:1]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\n", errout_str(), type);
114114
check(type + " foo(" + type + " x) { return x << 31; }", dinit(CheckOptions, $.settings = &settings));
115-
ASSERT_EQUALS("", errout_str());
115+
ASSERT_EQUALS_MSG("", errout_str(), type);
116116
}
117117
}
118118
// signed types getting promoted to int sizeof(int) = 4 bytes

0 commit comments

Comments
 (0)