Fixed #3237 (Bug in parser of class operator functions)

This commit is contained in:
Erik Lax 2011-10-23 10:25:14 +02:00 committed by Daniel Marjamäki
parent 65380d16d6
commit b7ab1e7d7e
2 changed files with 22 additions and 0 deletions

View File

@ -9446,6 +9446,11 @@ void Tokenizer::simplifyOperatorName()
if (par && par->isName()) {
op += par->str();
par = par->next();
// merge namespaces eg. 'operator std :: string () const {'
if (par && par->str() == "::" && par->next() && par->next()->isName()) {
op += par->str();
par = par->next();
}
done = false;
}
if (Token::Match(par, "=|.|++|--|%op%")) {

View File

@ -294,6 +294,8 @@ private:
TEST_CASE(simplifyTypedefFunction7);
TEST_CASE(simplifyTypedefFunction8);
TEST_CASE(simplifyOperator1);
TEST_CASE(reverseArraySyntax)
TEST_CASE(simplify_numeric_condition)
TEST_CASE(simplify_condition);
@ -6168,6 +6170,21 @@ private:
ASSERT_EQUALS("", errout.str()); // make sure that there is no internal error
}
void simplifyOperator1() {
// #3237 - error merging namespaces with operators
const char code[] = "class c {\n"
"public:\n"
" operator std::string() const;\n"
" operator string() const;\n"
"};\n";
const char expected[] = "class c { "
"public: "
"operatorstd::string ( ) const ; "
"operatorstring ( ) const ; "
"} ;";
ASSERT_EQUALS(expected, tok(code));
}
void reverseArraySyntax() {
ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));
}