diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 538a48910..e65a46b26 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index b5496ffa9..fcf2b17dc 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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 ( ) ;\n}void fn2 ( 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..