Skip to content

Commit 35b00a5

Browse files
committed
Support rValue references in typedef (cppcheck-opensource#1823)
1 parent efab840 commit 35b00a5

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ void Tokenizer::simplifyTypedef()
687687
}
688688

689689
// check for pointers and references
690-
while (Token::Match(tokOffset, "*|&|const")) {
690+
while (Token::Match(tokOffset, "*|&|&&|const")) {
691691
pointers.push_back(tokOffset->str());
692692
tokOffset = tokOffset->next();
693693
}

test/testsimplifytokens.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ class TestSimplifyTokens : public TestFixture {
304304
TEST_CASE(simplifyTypedef106); // ticket #3619
305305
TEST_CASE(simplifyTypedef107); // ticket #3963 - bad code => segmentation fault
306306
TEST_CASE(simplifyTypedef108); // ticket #4777
307+
TEST_CASE(simplifyTypedef109); // ticket #1823 - rvalue reference
307308

308309
TEST_CASE(simplifyTypedefFunction1);
309310
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@@ -5725,6 +5726,16 @@ class TestSimplifyTokens : public TestFixture {
57255726
ASSERT_EQUALS(expected, tok(code));
57265727
}
57275728

5729+
void simplifyTypedef109() {
5730+
const char code[] = "typedef int&& rref;\n"
5731+
"rref var;";
5732+
const char expected[] = "int & & var ;";
5733+
5734+
checkSimplifyTypedef(code);
5735+
ASSERT_EQUALS(expected, tok(code));
5736+
ASSERT_EQUALS("", errout.str());
5737+
}
5738+
57285739
void simplifyTypedefFunction1() {
57295740
{
57305741
const char code[] = "typedef void (*my_func)();\n"

0 commit comments

Comments
 (0)