Tokenizer::simplifyTypedef: Better handling of r-value references
This commit is contained in:
parent
37a4e375ba
commit
8e9d7290b2
|
@ -1534,13 +1534,15 @@ void Tokenizer::simplifyTypedef()
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
|
|
||||||
// reference or pointer to array?
|
// reference or pointer to array?
|
||||||
if (tok2->str() == "&" || tok2->str() == "*") {
|
if (Token::Match(tok2, "&|*|&&")) {
|
||||||
tok2 = tok2->previous();
|
tok2 = tok2->previous();
|
||||||
tok2->insertToken("(");
|
tok2->insertToken("(");
|
||||||
Token *tok3 = tok2->next();
|
Token *tok3 = tok2->next();
|
||||||
|
|
||||||
// handle missing variable name
|
// handle missing variable name
|
||||||
if (tok2->strAt(3) == ")" || tok2->strAt(3) == "," || tok2->strAt(3) == "(")
|
if (Token::Match(tok3, "( *|&|&& *|&|&& %name%"))
|
||||||
|
tok2 = tok3->tokAt(3);
|
||||||
|
else if (Token::Match(tok2->tokAt(3), "[(),]"))
|
||||||
tok2 = tok2->tokAt(2);
|
tok2 = tok2->tokAt(2);
|
||||||
else
|
else
|
||||||
tok2 = tok2->tokAt(3);
|
tok2 = tok2->tokAt(3);
|
||||||
|
|
|
@ -166,6 +166,7 @@ private:
|
||||||
TEST_CASE(simplifyTypedef128); // ticket #9053
|
TEST_CASE(simplifyTypedef128); // ticket #9053
|
||||||
TEST_CASE(simplifyTypedef129);
|
TEST_CASE(simplifyTypedef129);
|
||||||
TEST_CASE(simplifyTypedef130); // ticket #9446
|
TEST_CASE(simplifyTypedef130); // ticket #9446
|
||||||
|
TEST_CASE(simplifyTypedef131); // ticket #9446
|
||||||
|
|
||||||
TEST_CASE(simplifyTypedefFunction1);
|
TEST_CASE(simplifyTypedefFunction1);
|
||||||
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
|
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
|
||||||
|
@ -2616,6 +2617,22 @@ private:
|
||||||
ASSERT_EQUALS(exp, tok(code, false));
|
ASSERT_EQUALS(exp, tok(code, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void simplifyTypedef131() {
|
||||||
|
const char code[] = "typedef unsigned char a4[4];\n"
|
||||||
|
"a4 a4obj;\n"
|
||||||
|
"a4 && a4_rref = std::move(a4obj);\n"
|
||||||
|
"a4* a4p = &(a4obj);\n"
|
||||||
|
"a4*&& a4p_rref = std::move(a4p);";
|
||||||
|
|
||||||
|
const char exp [] = "unsigned char a4obj [ 4 ] ; "
|
||||||
|
"unsigned char ( && a4_rref ) [ 4 ] = std :: move ( a4obj ) ; "
|
||||||
|
"unsigned char ( * a4p ) [ 4 ] ; "
|
||||||
|
"a4p = & ( a4obj ) ; "
|
||||||
|
"unsigned char ( * && a4p_rref ) [ 4 ] = std :: move ( a4p ) ;";
|
||||||
|
|
||||||
|
ASSERT_EQUALS(exp, tok(code, false));
|
||||||
|
}
|
||||||
|
|
||||||
void simplifyTypedefFunction1() {
|
void simplifyTypedefFunction1() {
|
||||||
{
|
{
|
||||||
const char code[] = "typedef void (*my_func)();\n"
|
const char code[] = "typedef void (*my_func)();\n"
|
||||||
|
|
Loading…
Reference in New Issue