#1943 (segmentation fault of cppcheck (= default))

This commit is contained in:
Daniel Marjamäki 2010-08-17 19:50:21 +02:00
parent 1faaa5471c
commit aa00587fed
2 changed files with 51 additions and 0 deletions

View File

@ -1749,6 +1749,37 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s
}
}
// Remove "= default|delete" inside class|struct definitions
// Todo: Remove it if it is used "externally" too.
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (Token::Match(tok, "struct|class %var% :|{"))
{
unsigned int indentlevel = 0;
for (Token * tok2 = tok->tokAt(2); tok2; tok2 = tok2->next())
{
if (tok2->str() == "{")
++indentlevel;
else if (tok2->str() == "}")
{
if (indentlevel <= 1)
break;
--indentlevel;
}
else if (indentlevel == 1 && Token::Match(tok2, ") = delete|default ;"))
{
const Token *end = tok2->tokAt(4);
tok2 = tok2->link()->previous();
while ((tok2->isName() && tok2->str().find(":") == std::string::npos) ||
Token::Match(tok2, "[&*~]"))
tok2 = tok2->previous();
if (Token::Match(tok2, "[;{}]") || tok2->isName())
Token::eraseTokens(tok2, end);
}
}
}
}
// Remove __declspec()
simplifyDeclspec();

View File

@ -231,6 +231,7 @@ private:
TEST_CASE(removedeclspec);
TEST_CASE(removeattribute);
TEST_CASE(cpp0xtemplate);
TEST_CASE(cpp0xdefault);
TEST_CASE(arraySize);
@ -3874,6 +3875,25 @@ private:
ASSERT_EQUALS(";\n\n\nint main ( )\n{\nfn2<int> ( ) ;\n}void fn2<int> ( int t = [ ] { return 1 ; } ( ) )\n{ }", tokenizeAndStringify(code));
}
void cpp0xdefault()
{
{
const char *code = "struct foo {"
" foo() = default;"
"}";
ASSERT_EQUALS("struct foo { }", tokenizeAndStringify(code));
}
{
const char *code = "struct foo {"
" foo();"
"}"
"foo::foo() = delete;";
ASSERT_EQUALS("struct foo { foo ( ) ; } foo :: foo ( ) = delete ;", tokenizeAndStringify(code));
TODO_ASSERT_EQUALS("struct foo { }", tokenizeAndStringify(code));
}
}
std::string arraySize_(const std::string &code)
{
// tokenize..