From 0fb680d887876b3b57b20f4c7a0b823e29498bec Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Fri, 19 Mar 2010 19:04:56 +0100 Subject: [PATCH] Tokenizer: remove unnamed anonymous structures and unions (#1493) --- lib/tokenize.cpp | 10 ++++++++++ test/testclass.cpp | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ea6263988..8e589a603 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6854,6 +6854,16 @@ void Tokenizer::simplifyStructDecl() tok = tok->next(); tok->insertToken(name.c_str()); } + else if (tok->next()->str() == ";") + { + Token *previous = tok1->previous(); + previous->deleteNext(); + previous->deleteNext(); + tok1 = previous->next(); + previous = tok->previous(); + previous->deleteNext(); + previous->deleteNext(); + } tok = tok1->next(); } diff --git a/test/testclass.cpp b/test/testclass.cpp index 6c26d24d5..3cfa1aa2f 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -2100,6 +2100,20 @@ private: " void foo() { }\n" "};"); ASSERT_EQUALS("[test.cpp:4]: (style) The function 'Fred::foo' can be const\n", errout.str()); + + checkConst("struct fast_string\n" + "{\n" + " union\n" + " {\n" + " char buff[100];\n" + " };\n" + " void set_type(char t);\n" + "};\n" + "inline void fast_string::set_type(char t)\n" + "{\n" + " buff[10] = t;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void const7()