Skip to content

Commit 93fd884

Browse files
authored
fixed #13363 - apply default signedness to char only (#7155)
1 parent b901fbe commit 93fd884

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/symboldatabase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7185,7 +7185,7 @@ static const Token* parsedecl(const Token* type,
71857185
else if (enum_type->isUnsigned())
71867186
valuetype->sign = ValueType::Sign::UNSIGNED;
71877187
else
7188-
valuetype->sign = defaultSignedness;
7188+
valuetype->sign = defaultSignedness; // TODO: this is implementation-dependent might be separate from char
71897189
const ValueType::Type t = ValueType::typeFromString(enum_type->str(), enum_type->isLong());
71907190
if (t != ValueType::Type::UNKNOWN_TYPE)
71917191
valuetype->type = t;
@@ -7586,7 +7586,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
75867586
else if (tok->previous()->isSigned())
75877587
valuetype.sign = ValueType::Sign::SIGNED;
75887588
else if (valuetype.isIntegral() && valuetype.type != ValueType::UNKNOWN_INT)
7589-
valuetype.sign = mDefaultSignedness;
7589+
valuetype.sign = (valuetype.type == ValueType::Type::CHAR) ? mDefaultSignedness : ValueType::Sign::SIGNED;
75907590
setValueType(tok, valuetype);
75917591
}
75927592

test/testio.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class TestIO : public TestFixture {
7777
TEST_CASE(testPrintfParenthesis); // #8489
7878
TEST_CASE(testStdDistance); // #10304
7979
TEST_CASE(testParameterPack); // #11289
80+
81+
TEST_CASE(testDefaultSignInt); // #13363
8082
}
8183

8284
struct CheckOptions
@@ -85,6 +87,7 @@ class TestIO : public TestFixture {
8587
bool inconclusive = false;
8688
bool portability = false;
8789
Platform::Type platform = Platform::Type::Unspecified;
90+
char defaultSign = '\0';
8891
bool onlyFormatStr = false;
8992
bool cpp = true;
9093
};
@@ -96,6 +99,7 @@ class TestIO : public TestFixture {
9699
settings1.severity.setEnabled(Severity::portability, options.portability);
97100
settings1.certainty.setEnabled(Certainty::inconclusive, options.inconclusive);
98101
PLATFORM(settings1.platform, options.platform);
102+
settings1.platform.defaultSign = options.defaultSign;
99103

100104
// Tokenize..
101105
SimpleTokenizer tokenizer(settings1, *this);
@@ -4933,6 +4937,22 @@ class TestIO : public TestFixture {
49334937
"}\n");
49344938
ASSERT_EQUALS("", errout_str());
49354939
}
4940+
4941+
// TODO: we need to run big tests with a platform that has unsigned chars
4942+
void testDefaultSignInt() { // #13363
4943+
// Platform::defaultSign should only affect char
4944+
const char code[] =
4945+
"void f() {\n"
4946+
" double d = 1\n;"
4947+
" printf(\"%i\", int(d));\n"
4948+
"}\n";
4949+
check(code);
4950+
ASSERT_EQUALS("", errout_str());
4951+
check(code, dinit(CheckOptions, $.defaultSign = 's'));
4952+
ASSERT_EQUALS("", errout_str());
4953+
check(code, dinit(CheckOptions, $.defaultSign = 'u'));
4954+
ASSERT_EQUALS("", errout_str());
4955+
}
49364956
};
49374957

49384958
REGISTER_TEST(TestIO)

0 commit comments

Comments
 (0)