Fixed #1891 (Internal error when enum assigned to sizeof without brackets)

This commit is contained in:
Daniel Marjamäki 2010-07-22 22:21:12 +02:00
parent f69109fbf6
commit e1612bc175
2 changed files with 49 additions and 0 deletions

View File

@ -3173,6 +3173,28 @@ void Tokenizer::simplifySizeof()
if (Token::simpleMatch(tok->next(), "sizeof"))
continue;
// sizeof 'x'
if (tok->strAt(1)[0] == '\'')
{
tok->deleteThis();
std::ostringstream sz;
sz << sizeof 'x';
tok->str(sz.str());
continue;
}
// sizeof('x')
if (Token::Match(tok, "sizeof ( %any% )") && tok->strAt(2)[0] == '\'')
{
tok->deleteThis();
tok->deleteThis();
tok->deleteNext();
std::ostringstream sz;
sz << sizeof 'x';
tok->str(sz.str());
continue;
}
// sizeof "text"
if (Token::Match(tok->next(), "%str%"))
{

View File

@ -79,6 +79,7 @@ private:
TEST_CASE(sizeof16);
TEST_CASE(sizeof17);
TEST_CASE(sizeof18);
TEST_CASE(sizeof19); // #1891 - sizeof 'x'
TEST_CASE(sizeofsizeof);
TEST_CASE(casting);
@ -1288,6 +1289,32 @@ private:
}
}
void sizeof19()
{
// ticket #1891 - sizeof 'x'
{
const char code[] = "void f()\n"
"{\n"
" sizeof 'x';\n"
"}\n";
std::ostringstream sz;
sz << sizeof('x');
ASSERT_EQUALS("void f ( ) { " + sz.str() + " ; }", tok(code));
ASSERT_EQUALS("", errout.str());
}
{
const char code[] = "void f()\n"
"{\n"
" sizeof('x');\n"
"}\n";
std::ostringstream sz;
sz << sizeof('x');
ASSERT_EQUALS("void f ( ) { " + sz.str() + " ; }", tok(code));
ASSERT_EQUALS("", errout.str());
}
}
void sizeofsizeof()
{
// ticket #1682