Skip to content

Commit e71ed28

Browse files
authored
fix #14034: AST broken for 'or' keyword (danmar#7698)
1 parent c2b02bd commit e71ed28

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7682,7 +7682,7 @@ bool Tokenizer::simplifyCAlternativeTokens()
76827682
if (isC() && Token::Match(tok->previous(), "%type%|* %name% [;,=]"))
76837683
return false;
76847684

7685-
if (!Token::Match(tok->previous(), "%name%|%num%|%char%|)|]|> %name% %name%|%num%|%char%|%op%|("))
7685+
if (!Token::Match(tok->previous(), "%name%|%num%|%char%|%str%|)|]|> %name% %name%|%num%|%char%|%op%|%str%|("))
76867686
continue;
76877687
if (Token::Match(tok->next(), "%assign%|%or%|%oror%|&&|*|/|%|^") && !Token::Match(tok->previous(), "%num%|%char%|) %name% *"))
76887688
continue;

test/testtokenize.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ class TestTokenizer : public TestFixture {
405405
TEST_CASE(astdecltypescope);
406406
TEST_CASE(astdesignatedinit);
407407
TEST_CASE(astrvaluedecl);
408+
TEST_CASE(astorkeyword);
408409

409410
TEST_CASE(startOfExecutableScope);
410411

@@ -6205,6 +6206,7 @@ class TestTokenizer : public TestFixture {
62056206
tokenizer.simplifySpaceshipOperator();
62066207
tokenizer.createLinks();
62076208
tokenizer.createLinks2();
6209+
tokenizer.simplifyCAlternativeTokens();
62086210
tokenizer.list.front()->assignIndexes();
62096211

62106212
// set varid..
@@ -7188,6 +7190,10 @@ class TestTokenizer : public TestFixture {
71887190
ASSERT_EQUALS("varstdmove::var(=", testAst("std::string&& var = std::move(var);"));
71897191
}
71907192

7193+
void astorkeyword() {
7194+
ASSERT_EQUALS("ifsp.\"\"==sp.0==||(", testAst("void f() { if (s.p == \"\" or s.p == 0) {} }"));
7195+
}
7196+
71917197
#define isStartOfExecutableScope(offset, code) isStartOfExecutableScope_(offset, code, __FILE__, __LINE__)
71927198
template<size_t size>
71937199
bool isStartOfExecutableScope_(int offset, const char (&code)[size], const char* file, int line) {

0 commit comments

Comments
 (0)