Skip to content

Commit 0fca962

Browse files
authored
fix #13893: Tokenizer: isInitBracket property is set for namespace (#7556)
1 parent 285a80e commit 0fca962

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/tokenize.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7721,8 +7721,11 @@ void Tokenizer::simplifyInitVar()
77217721
continue;
77227722

77237723
if (Token::Match(tok, "%type% *|&| %name% (|{")) {
7724+
bool isNamespace = Token::simpleMatch(tok, "namespace");
77247725
while (tok && !Token::Match(tok, "(|{"))
77257726
tok = tok->next();
7727+
if (isNamespace)
7728+
continue;
77267729
if (tok)
77277730
tok->isInitBracket(true);
77287731
/* tok = initVar(tok);

test/testtokenize.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4518,6 +4518,14 @@ class TestTokenizer : public TestFixture {
45184518
ASSERT_EQUALS("{ return doSomething ( X ) , 0 ; }", tokenizeAndStringify(code));
45194519
ASSERT_EQUALS("", errout_str());
45204520
}
4521+
4522+
{
4523+
// 13893
4524+
const char code[] = "namespace test { bool foo; }";
4525+
SimpleTokenizer tokenizer(settings0, *this);
4526+
ASSERT(tokenizer.tokenize(code));
4527+
ASSERT(!tokenizer.tokens()->tokAt(2)->isInitBracket());
4528+
}
45214529
}
45224530

45234531
void simplifyInitVar2() {

0 commit comments

Comments
 (0)