Partial fix ticket #3385 ('throw' isn't removed if the argument of the function is type 'struct|class').

This commit is contained in:
Edoardo Prezioso 2011-12-06 20:36:23 +01:00
parent 4884a1dfe0
commit eb5fe250ab
2 changed files with 36 additions and 3 deletions

View File

@ -8816,16 +8816,24 @@ void Tokenizer::removeExceptionSpecifications(Token *tok) const
tok->deleteNext();
}
else if (Token::Match(tok, "class|namespace|struct %type%")) {
else if (Token::Match(tok, "class|namespace|struct %type% :|{")) {
tok = tok->tokAt(2);
while (tok && !Token::Match(tok, "[;{=]"))
tok = tok->next();
if (tok && tok->str() == "{") {
removeExceptionSpecifications(tok->next());
tok = tok->link();
}
} else
continue;
}
tok = tok ? tok->next() : 0;
else if (Token::simpleMatch(tok, "namespace {")) {
tok = tok->next();
removeExceptionSpecifications(tok->next());
tok = tok->link();
}
tok = tok->next();
}
}

View File

@ -297,6 +297,8 @@ private:
TEST_CASE(removeExceptionSpecification1);
TEST_CASE(removeExceptionSpecification2);
TEST_CASE(removeExceptionSpecification3);
TEST_CASE(removeExceptionSpecification4);
TEST_CASE(removeExceptionSpecification5);
TEST_CASE(gt); // use "<" comparisons instead of ">"
@ -4852,6 +4854,29 @@ private:
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
}
void removeExceptionSpecification4() {
const char code[] = "namespace {\n"
" void B() throw ();\n"
"};";
const char expected[] = "namespace {\n"
"void B ( ) ;\n"
"} ;";
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
}
void removeExceptionSpecification5() {
ASSERT_EQUALS("void foo ( struct S ) ;",
tokenizeAndStringify("void foo (struct S) throw();"));
ASSERT_EQUALS("void foo ( struct S , int ) ;",
tokenizeAndStringify("void foo (struct S, int) throw();"));
ASSERT_EQUALS("void foo ( int , struct S ) ;",
tokenizeAndStringify("void foo (int, struct S) throw();"));
ASSERT_EQUALS("void foo ( struct S1 , struct S2 ) ;",
tokenizeAndStringify("void foo (struct S1, struct S2) throw();"));
}
void gt() {
ASSERT_EQUALS("( i < 10 )", tokenizeAndStringify("(10>i)"));