Skip to content

Commit f69ab38

Browse files
committed
TokenList: added missing standards checks
1 parent e3b3048 commit f69ab38

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

lib/tokenlist.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,7 @@ void TokenList::simplifyPlatformTypes()
18541854
if (!mSettings)
18551855
return;
18561856

1857-
const bool isCPP11 = mSettings->standards.cpp >= Standards::CPP11;
1857+
const bool isCPP11 = mIsCpp && (mSettings->standards.cpp >= Standards::CPP11);
18581858

18591859
enum { isLongLong, isLong, isInt } type;
18601860

@@ -1996,7 +1996,7 @@ void TokenList::simplifyStdType()
19961996
continue;
19971997
}
19981998

1999-
if (Token::Match(tok, "char|short|int|long|unsigned|signed|double|float") || (mSettings->standards.c >= Standards::C99 && Token::Match(tok, "complex|_Complex"))) {
1999+
if (Token::Match(tok, "char|short|int|long|unsigned|signed|double|float") || (mIsC && (mSettings->standards.c >= Standards::C99) && Token::Match(tok, "complex|_Complex"))) {
20002000
bool isFloat= false;
20012001
bool isSigned = false;
20022002
bool isUnsigned = false;
@@ -2019,7 +2019,7 @@ void TokenList::simplifyStdType()
20192019
else if (Token::Match(tok2, "float|double")) {
20202020
isFloat = true;
20212021
typeSpec = tok2;
2022-
} else if (mSettings->standards.c >= Standards::C99 && Token::Match(tok2, "complex|_Complex"))
2022+
} else if (mIsC && (mSettings->standards.c >= Standards::C99) && Token::Match(tok2, "complex|_Complex"))
20232023
isComplex = !isFloat || tok2->str() == "_Complex" || Token::Match(tok2->next(), "*|&|%name%"); // Ensure that "complex" is not the variables name
20242024
else if (Token::Match(tok2, "char|int")) {
20252025
if (!typeSpec)

test/testtokenize.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2873,28 +2873,33 @@ class TestTokenizer : public TestFixture {
28732873
}
28742874
{
28752875
const char code[] = "float complex x;";
2876-
const char expected[] = "_Complex float x ;";
2876+
const char expected[] = "float complex x ;";
28772877
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
28782878
}
2879+
{
2880+
const char code[] = "float complex x;";
2881+
const char expected[] = "_Complex float x ;";
2882+
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, Platform::Native, "test.c"));
2883+
}
28792884
{
28802885
const char code[] = "complex float x;";
28812886
const char expected[] = "_Complex float x ;";
2882-
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
2887+
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, Platform::Native, "test.c"));
28832888
}
28842889
{
28852890
const char code[] = "complex long double x;";
28862891
const char expected[] = "_Complex long double x ;";
2887-
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
2892+
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, Platform::Native, "test.c"));
28882893
}
28892894
{
28902895
const char code[] = "long double complex x;";
28912896
const char expected[] = "_Complex long double x ;";
2892-
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
2897+
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, Platform::Native, "test.c"));
28932898
}
28942899
{
28952900
const char code[] = "double complex;";
28962901
const char expected[] = "double complex ;";
2897-
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
2902+
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, Platform::Native, "test.c"));
28982903
}
28992904
}
29002905

0 commit comments

Comments
 (0)