Skip to content

Commit

Permalink
fixed #13363 - apply default signedness to char only (#7155)
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave authored Jan 12, 2025
1 parent b901fbe commit 93fd884
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7185,7 +7185,7 @@ static const Token* parsedecl(const Token* type,
else if (enum_type->isUnsigned())
valuetype->sign = ValueType::Sign::UNSIGNED;
else
valuetype->sign = defaultSignedness;
valuetype->sign = defaultSignedness; // TODO: this is implementation-dependent might be separate from char
const ValueType::Type t = ValueType::typeFromString(enum_type->str(), enum_type->isLong());
if (t != ValueType::Type::UNKNOWN_TYPE)
valuetype->type = t;
Expand Down Expand Up @@ -7586,7 +7586,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
else if (tok->previous()->isSigned())
valuetype.sign = ValueType::Sign::SIGNED;
else if (valuetype.isIntegral() && valuetype.type != ValueType::UNKNOWN_INT)
valuetype.sign = mDefaultSignedness;
valuetype.sign = (valuetype.type == ValueType::Type::CHAR) ? mDefaultSignedness : ValueType::Sign::SIGNED;
setValueType(tok, valuetype);
}

Expand Down
20 changes: 20 additions & 0 deletions test/testio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class TestIO : public TestFixture {
TEST_CASE(testPrintfParenthesis); // #8489
TEST_CASE(testStdDistance); // #10304
TEST_CASE(testParameterPack); // #11289

TEST_CASE(testDefaultSignInt); // #13363
}

struct CheckOptions
Expand All @@ -85,6 +87,7 @@ class TestIO : public TestFixture {
bool inconclusive = false;
bool portability = false;
Platform::Type platform = Platform::Type::Unspecified;
char defaultSign = '\0';
bool onlyFormatStr = false;
bool cpp = true;
};
Expand All @@ -96,6 +99,7 @@ class TestIO : public TestFixture {
settings1.severity.setEnabled(Severity::portability, options.portability);
settings1.certainty.setEnabled(Certainty::inconclusive, options.inconclusive);
PLATFORM(settings1.platform, options.platform);
settings1.platform.defaultSign = options.defaultSign;

// Tokenize..
SimpleTokenizer tokenizer(settings1, *this);
Expand Down Expand Up @@ -4933,6 +4937,22 @@ class TestIO : public TestFixture {
"}\n");
ASSERT_EQUALS("", errout_str());
}

// TODO: we need to run big tests with a platform that has unsigned chars
void testDefaultSignInt() { // #13363
// Platform::defaultSign should only affect char
const char code[] =
"void f() {\n"
" double d = 1\n;"
" printf(\"%i\", int(d));\n"
"}\n";
check(code);
ASSERT_EQUALS("", errout_str());
check(code, dinit(CheckOptions, $.defaultSign = 's'));
ASSERT_EQUALS("", errout_str());
check(code, dinit(CheckOptions, $.defaultSign = 'u'));
ASSERT_EQUALS("", errout_str());
}
};

REGISTER_TEST(TestIO)

0 comments on commit 93fd884

Please sign in to comment.