Fixed #5015 (strings not being concatinated properly)

This commit is contained in:
Robert Reif 2013-09-06 05:36:33 +02:00 committed by Daniel Marjamäki
parent 56680ef399
commit 489a3a6e53
3 changed files with 37 additions and 8 deletions

View File

@ -993,7 +993,7 @@ void Token::stringify(std::ostream& os, bool varid, bool attributes) const
else if (isSigned())
os << "signed ";
if (isLong()) {
if (_type == eString)
if (_type == eString || _type == eChar)
os << "L";
else
os << "long ";

View File

@ -9358,6 +9358,13 @@ void Tokenizer::simplifyMicrosoftStringFunctions()
tok->deleteNext();
tok->deleteThis();
tok->deleteNext();
while (tok->next() && Token::Match(tok->next(), "_T ( %char%|%str% )")) {
tok->next()->deleteNext();
tok->next()->deleteThis();
tok->next()->deleteNext();
tok->concatStr(tok->next()->str());
tok->deleteNext();
}
}
}
} else if (_settings->platformType == Settings::Win32W ||
@ -9401,6 +9408,14 @@ void Tokenizer::simplifyMicrosoftStringFunctions()
tok->deleteNext();
tok->deleteThis();
tok->deleteNext();
tok->isLong(true);
while (tok->next() && Token::Match(tok->next(), "_T ( %char%|%str% )")) {
tok->next()->deleteNext();
tok->next()->deleteThis();
tok->next()->deleteNext();
tok->concatStr(tok->next()->str());
tok->deleteNext();
}
}
}
}

View File

@ -493,6 +493,8 @@ private:
TEST_CASE(platformWin64);
TEST_CASE(platformUnix32);
TEST_CASE(platformUnix64);
TEST_CASE(platformWin32AStringCat); // ticket #5015
TEST_CASE(platformWin32WStringCat); // ticket #5015
TEST_CASE(simplifyMathExpressions); //ticket #1620
@ -8084,18 +8086,18 @@ private:
"const wchar_t * lpctstr ; "
"unsigned char tbyte ; "
"void foo ( ) { "
"wchar_t tc ; tc = \'c\' ; "
"wchar_t src [ 10 ] = \"123456789\" ; "
"wchar_t tc ; tc = L\'c\' ; "
"wchar_t src [ 10 ] = L\"123456789\" ; "
"wchar_t dst [ 10 ] ; "
"wcscpy ( dst , src ) ; "
"dst [ 0 ] = 0 ; "
"wcscat ( dst , src ) ; "
"wchar_t * d ; d = wcsdup ( str ) ; "
"wprintf ( \"Hello world!\n\" ) ; "
"swprintf ( dst , \"Hello!\n\" ) ; "
"snwprintf ( dst , sizeof ( dst ) / sizeof ( wchar_t ) , \"Hello world!\n\" ) ; "
"wscanf ( \"%s\" , dst ) ; "
"swscanf ( dst , \"%s\" , dst ) ; "
"wprintf ( L\"Hello world!\n\" ) ; "
"swprintf ( dst , L\"Hello!\n\" ) ; "
"snwprintf ( dst , sizeof ( dst ) / sizeof ( wchar_t ) , L\"Hello world!\n\" ) ; "
"wscanf ( L\"%s\" , dst ) ; "
"swscanf ( dst , L\"%s\" , dst ) ; "
"}";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, false, true, Settings::Win32W));
}
@ -8262,6 +8264,18 @@ private:
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Unix64));
}
void platformWin32AStringCat() { //#5150
const char code[] = "TCHAR text[] = _T(\"123\") _T(\"456\") _T(\"789\");";
const char expected[] = "char text [ 10 ] = \"123456789\" ;";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Win32A));
}
void platformWin32WStringCat() { //#5150
const char code[] = "TCHAR text[] = _T(\"123\") _T(\"456\") _T(\"789\");";
const char expected[] = "wchar_t text [ 10 ] = L\"123456789\" ;";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Win32W));
}
void simplifyMathExpressions() {//#1620
const char code1[] = "void foo() {\n"
" std::cout<<sin(0);\n"