Skip to content

Commit 650f4d5

Browse files
committed
fix
1 parent f1d88ed commit 650f4d5

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

lib/tokenize.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,13 +2651,13 @@ namespace {
26512651
}
26522652

26532653
if (Token::Match(tok1, "%name% (") && TokenList::isFunctionHead(tok1->next(), "{;:")) {
2654-
if (Token::Match(tok1->previous(), "%name%"))
2654+
if (Token::Match(tok1->previous(), "%name%") && !tok1->previous()->isControlFlowKeyword())
26552655
return false;
26562656
if (Token::Match(tok1->previous(), ">|>>") && tok1->previous()->link())
26572657
return false;
26582658
if (Token::Match(tok1->previous(), "*|&|&&")) {
26592659
const Token* prev = tok1->previous();
2660-
while (Token::Match(prev, "%name%|*|&|&&|::"))
2660+
while (Token::Match(prev, "%name%|*|&|&&|::") && !prev->isControlFlowKeyword())
26612661
prev = prev->previous();
26622662
if (Token::Match(prev, ">|>>") && tok1->previous()->link())
26632663
return false;
@@ -3012,18 +3012,12 @@ bool Tokenizer::simplifyUsing()
30123012
if (Token::Match(start, "class|struct|union|enum"))
30133013
start = start->next();
30143014

3015-
Token *startToken = usingEnd;
3016-
for (const Token* tok2 = nameToken->tokAt(2); Token::Match(tok2, "%name%|::"); tok2 = tok2->next()) {
3017-
if (Token::Match(tok2, "%name% <")) {
3018-
// Unfortunately we have to start searching from the beginning
3019-
// of the token stream because templates are instantiated at
3020-
// the end of the token stream and it may be used before then.
3021-
startToken = list.front();
3022-
}
3023-
}
3024-
3015+
// Unfortunately we have to start searching from the beginning
3016+
// of the token stream because templates are instantiated at
3017+
// the end of the token stream and it may be used before then.
30253018
ScopeInfo3 scopeInfo1;
30263019
ScopeInfo3 *currentScope1 = &scopeInfo1;
3020+
Token *startToken = list.front();
30273021
Token *endToken = nullptr;
30283022
bool inMemberFunc = false;
30293023
const ScopeInfo3 * memberFuncScope = nullptr;

test/testsimplifyusing.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class TestSimplifyUsing : public TestFixture {
9191
TEST_CASE(simplifyUsing10173);
9292
TEST_CASE(simplifyUsing10335);
9393
TEST_CASE(simplifyUsing10720);
94+
TEST_CASE(simplifyUsing13873); // function declaration
9495

9596
TEST_CASE(scopeInfo1);
9697
TEST_CASE(scopeInfo2);
@@ -1586,6 +1587,20 @@ class TestSimplifyUsing : public TestFixture {
15861587
TODO_ASSERT(startsWith(errout_str(), "[test.cpp:6]: (debug) Failed to parse 'using C = S < S < S < int"));
15871588
}
15881589

1590+
void simplifyUsing13873() { // function declaration
1591+
const char code1[] = "using NS1::f;\n"
1592+
"namespace NS1 { void f(); }\n";
1593+
ASSERT_EQUALS("namespace NS1 { void f ( ) ; }", tok(code1));
1594+
1595+
const char code2[] = "using NS1::f;\n"
1596+
"void bar() { f(); }\n";
1597+
ASSERT_EQUALS("void bar ( ) { NS1 :: f ( ) ; }", tok(code2));
1598+
1599+
const char code3[] = "using NS1::f;\n"
1600+
"namespace NS1 { void* f(); }\n";
1601+
ASSERT_EQUALS("namespace NS1 { void * f ( ) ; }", tok(code3));
1602+
}
1603+
15891604
void scopeInfo1() {
15901605
const char code[] = "struct A {\n"
15911606
" enum class Mode { UNKNOWN, ENABLED, NONE, };\n"

test/testtokenize.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ class TestTokenizer : public TestFixture {
480480
TEST_CASE(constFunctionPtrTypedef); // #12135
481481

482482
TEST_CASE(simplifyPlatformTypes);
483-
TEST_CASE(simplifyUsing1);
484483

485484
TEST_CASE(dumpFallthrough);
486485
}
@@ -8534,21 +8533,6 @@ class TestTokenizer : public TestFixture {
85348533
}
85358534
}
85368535

8537-
void simplifyUsing1() {
8538-
// #13873
8539-
const char code1[] = "using NS1::f;\n"
8540-
"namespace NS1 { void f(); }\n";
8541-
ASSERT_EQUALS("namespace NS1 { void f ( ) ; }", tokenizeAndStringify(code1));
8542-
8543-
const char code2[] = "using NS1::f;\n"
8544-
"void bar() { f(); }\n";
8545-
ASSERT_EQUALS("void bar ( ) { NS1 :: f ( ) ; }", tokenizeAndStringify(code2));
8546-
8547-
const char code3[] = "using NS1::f;\n"
8548-
"namespace NS1 { void* f(); }\n";
8549-
ASSERT_EQUALS("namespace NS1 { void * f ( ) ; }", tokenizeAndStringify(code3));
8550-
}
8551-
85528536
void dumpFallthrough() {
85538537
const char * code = "void f(int n) {\n"
85548538
" void g(), h(), i();\n"

0 commit comments

Comments
 (0)