Skip to content

Commit 25fe1de

Browse files
Fix #14548 internalAstError for compound literal in ternary operator (danmar#8283)
1 parent f27f35b commit 25fe1de

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/tokenlist.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ static void compileTerm(Token *&tok, AST_state& state)
873873
state.inArrayAssignment--;
874874
tok = tok1->link()->next();
875875
}
876-
} else if (!state.inArrayAssignment && !Token::simpleMatch(prev, "=")) {
876+
} else if ((!state.inArrayAssignment && !Token::simpleMatch(prev, "=")) || Token::simpleMatch(prev, "?")) {
877877
state.op.push(tok);
878878
tok = tok->link()->next();
879879
} else {

test/testtokenize.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ class TestTokenizer : public TestFixture {
426426
TEST_CASE(astrvaluedecl);
427427
TEST_CASE(astorkeyword);
428428
TEST_CASE(astenumdecl);
429+
TEST_CASE(astcompound);
429430

430431
TEST_CASE(startOfExecutableScope);
431432

@@ -7422,6 +7423,11 @@ class TestTokenizer : public TestFixture {
74227423
ASSERT_EQUALS("A0U=", testAst("enum myclass : unsigned char { A = 0U, };"));
74237424
}
74247425

7426+
void astcompound() {
7427+
ASSERT_EQUALS("sn0=={(tmp:?=", testAst("Str s = n == 0 ? (Str) { 0 } : tmp;")); // #14548
7428+
ASSERT_EQUALS("s(sstrlens(0:?,{(return", testAst("return (struct Str) { (unsigned char*)s, s ? strlen(s) : 0 };"));
7429+
}
7430+
74257431
#define isStartOfExecutableScope(offset, code) isStartOfExecutableScope_(offset, code, __FILE__, __LINE__)
74267432
template<size_t size>
74277433
bool isStartOfExecutableScope_(int offset, const char (&code)[size], const char* file, int line) {

0 commit comments

Comments
 (0)