Fixed #2232 (segmentation fault of cppcheck)

This commit is contained in:
Daniel Marjamäki 2010-11-29 17:46:10 +01:00
parent 564d896715
commit add8584612
2 changed files with 26 additions and 0 deletions

View File

@ -3551,6 +3551,11 @@ void Tokenizer::simplifySizeof()
if (Token::simpleMatch(tok->next(), "sizeof")) if (Token::simpleMatch(tok->next(), "sizeof"))
continue; continue;
if (Token::simpleMatch(tok->next(), ". . ."))
{
Token::eraseTokens(tok, tok->tokAt(4));
}
// sizeof 'x' // sizeof 'x'
if (tok->strAt(1)[0] == '\'') if (tok->strAt(1)[0] == '\'')
{ {

View File

@ -83,6 +83,7 @@ private:
TEST_CASE(sizeof18); TEST_CASE(sizeof18);
TEST_CASE(sizeof19); // #1891 - sizeof 'x' TEST_CASE(sizeof19); // #1891 - sizeof 'x'
TEST_CASE(sizeof20); // #2024 - sizeof a) TEST_CASE(sizeof20); // #2024 - sizeof a)
TEST_CASE(sizeof21); // #2232 - sizeof...(Args)
TEST_CASE(sizeofsizeof); TEST_CASE(sizeofsizeof);
TEST_CASE(casting); TEST_CASE(casting);
@ -1361,6 +1362,26 @@ private:
"}", tok(code)); "}", tok(code));
} }
void sizeof21()
{
// ticket #2232 - sizeof...(Args)
const char code[] = "struct Internal {\n"
" int operator()(const Args&... args) const {\n"
" int n = sizeof...(Args);\n"
" return n;\n"
" }\n"
"};\n"
"\n"
"int main() {\n"
" Internal internal;\n"
" int n = 0; n = internal(1);\n"
" return 0;\n"
"}\n";
// don't segfault
tok(code);
}
void sizeofsizeof() void sizeofsizeof()
{ {