Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2032,10 +2032,10 @@ void TokenList::simplifyPlatformTypes()

/** @todo This assumes a flat address space. Not true for segmented address space (FAR *). */

if (mSettings->platform.sizeof_size_t == mSettings->platform.sizeof_long)
type = isLong;
else if (mSettings->platform.sizeof_size_t == mSettings->platform.sizeof_long_long)
if (mSettings->platform.sizeof_size_t == mSettings->platform.sizeof_long_long)
type = isLongLong;
else if (mSettings->platform.sizeof_size_t == mSettings->platform.sizeof_long)
type = isLong;
else if (mSettings->platform.sizeof_size_t == mSettings->platform.sizeof_int)
type = isInt;
else
Expand Down
20 changes: 20 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ class TestTokenizer : public TestFixture {

TEST_CASE(atomicCast); // #12605
TEST_CASE(constFunctionPtrTypedef); // #12135

TEST_CASE(simplifyPlatformTypes);
}

#define tokenizeAndStringify(...) tokenizeAndStringify_(__FILE__, __LINE__, __VA_ARGS__)
Expand Down Expand Up @@ -8495,6 +8497,24 @@ class TestTokenizer : public TestFixture {
ASSERT_NO_THROW(tokenizeAndStringify(code));
ASSERT_EQUALS("void ( * const f ) ( ) ;", tokenizeAndStringify("typedef void (*fp_t)(); fp_t const f;"));
}

void simplifyPlatformTypes() {
{
const char code[] = "size_t f();";
ASSERT_EQUALS("unsigned long f ( ) ;", tokenizeAndStringify(code, true, Platform::Type::Unix32));
ASSERT_EQUALS("unsigned long long f ( ) ;", tokenizeAndStringify(code, true, Platform::Type::Unix64));
}
{
const char code[] = "ssize_t f();";
ASSERT_EQUALS("long f ( ) ;", tokenizeAndStringify(code, true, Platform::Type::Unix32));
ASSERT_EQUALS("long long f ( ) ;", tokenizeAndStringify(code, true, Platform::Type::Unix64));
}
{
const char code[] = "std::ptrdiff_t f();";
ASSERT_EQUALS("long f ( ) ;", tokenizeAndStringify(code, true, Platform::Type::Unix32));
ASSERT_EQUALS("long long f ( ) ;", tokenizeAndStringify(code, true, Platform::Type::Unix64));
}
}
};

REGISTER_TEST(TestTokenizer)
Expand Down
2 changes: 1 addition & 1 deletion test/testtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ class TestType : public TestFixture {
check("size_t f(int x, int y) {\n"
" return x * y;\n"
"}\n", settings);
ASSERT_EQUALS("[test.cpp:2]: (style) int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information.\n", errout_str());
ASSERT_EQUALS("[test.cpp:2]: (style) int result is returned as long value. If the return value is long long to avoid loss of information, then you have loss of information.\n", errout_str());
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Off-topic but this message is very confusing.

}

// This function ensure that test works with different compilers. Floats can
Expand Down
2 changes: 1 addition & 1 deletion test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2787,7 +2787,7 @@ class TestVarID : public TestFixture {
void varid_using() {
// #3648
const char code[] = "using std::size_t;";
const char expected[] = "1: using unsigned long ;\n";
const char expected[] = "1: using unsigned long long ;\n";
ASSERT_EQUALS(expected, tokenize(code));
}

Expand Down