Skip to content

Commit e12b29b

Browse files
committed
Fix #14457 (ValueType: char expression without signedness)
1 parent 803fdfe commit e12b29b

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

lib/symboldatabase.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7636,9 +7636,7 @@ static const Token* parsedecl(const Token* type,
76367636

76377637
// Set signedness for integral types..
76387638
if (valuetype->isIntegral() && valuetype->sign == ValueType::Sign::UNKNOWN_SIGN) {
7639-
if (valuetype->type == ValueType::Type::CHAR)
7640-
valuetype->sign = defaultSignedness;
7641-
else if (valuetype->type >= ValueType::Type::SHORT)
7639+
if (valuetype->type >= ValueType::Type::SHORT)
76427640
valuetype->sign = ValueType::Sign::SIGNED;
76437641
}
76447642

@@ -8756,7 +8754,7 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
87568754
return ValueType::MatchResult::UNKNOWN;
87578755
}
87588756

8759-
if (call->isIntegral() && func->isIntegral() && call->sign != ValueType::Sign::UNKNOWN_SIGN && func->sign != ValueType::Sign::UNKNOWN_SIGN && call->sign != func->sign)
8757+
if (call->isIntegral() && func->isIntegral() && call->sign != func->sign)
87608758
return ValueType::MatchResult::FALLBACK1;
87618759

87628760
if (func->reference != Reference::None && (func->constness > call->constness || func->volatileness > call->volatileness))

test/testsymboldatabase.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ class TestSymbolDatabase : public TestFixture {
586586
TEST_CASE(valueType2);
587587
TEST_CASE(valueType3);
588588
TEST_CASE(valueTypeThis);
589+
TEST_CASE(valueTypeChar);
589590

590591
TEST_CASE(variadic1); // #7453
591592
TEST_CASE(variadic2); // #7649
@@ -7796,20 +7797,12 @@ class TestSymbolDatabase : public TestFixture {
77967797
f = Token::findsimplematch(tokenizer.tokens(), "get ( get ( v7 ) ) ;");
77977798
ASSERT(f);
77987799
ASSERT(f->function());
7799-
if (std::numeric_limits<char>::is_signed) {
7800-
ASSERT_EQUALS(10, f->function()->tokenDef->linenr());
7801-
} else {
7802-
ASSERT_EQUALS(5, f->function()->tokenDef->linenr());
7803-
}
7800+
ASSERT_EQUALS(10, f->function()->tokenDef->linenr());
78047801

78057802
f = Token::findsimplematch(tokenizer.tokens(), "get ( get ( v8 ) ) ;");
78067803
ASSERT(f);
78077804
ASSERT(f->function());
7808-
if (std::numeric_limits<char>::is_signed) {
7809-
ASSERT_EQUALS(5, f->function()->tokenDef->linenr());
7810-
} else {
7811-
ASSERT_EQUALS(11, f->function()->tokenDef->linenr());
7812-
}
7805+
ASSERT_EQUALS(11, f->function()->tokenDef->linenr());
78137806

78147807
f = Token::findsimplematch(tokenizer.tokens(), "get ( get ( v9 ) ) ;");
78157808
ASSERT(f);
@@ -10145,6 +10138,13 @@ class TestSymbolDatabase : public TestFixture {
1014510138
ASSERT_EQUALS("const C *", typeOf("class C { void foo() const; }; void C::foo() const { *this = 0; }", "this"));
1014610139
}
1014710140

10141+
void valueTypeChar() {
10142+
Settings s = settings2;
10143+
s.platform.defaultSign = 's';
10144+
ASSERT_EQUALS("char", typeOf("char c; c = 'x';", "c =", true, &s));
10145+
ASSERT_EQUALS("char", typeOf("char buf[10]; buf[0] = 'x';", "[ 0 ]", true, &s));
10146+
}
10147+
1014810148
void variadic1() { // #7453
1014910149
{
1015010150
GET_SYMBOL_DB("CBase* create(const char *c1, ...);\n"

0 commit comments

Comments
 (0)