Skip to content

Commit 1bed43d

Browse files
authored
fix #14010: False constParameterReference ignoring call with designated-initializer & #14018: Invalid AST for function call with designated initializer (danmar#7673)
1 parent b62f571 commit 1bed43d

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

lib/tokenlist.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ static void compileTerm(Token *&tok, AST_state& state)
831831
} else if ((state.cpp && iscpp11init(tok)) || Token::simpleMatch(tok->previous(), "] {")) {
832832
Token *const end = tok->link();
833833
if (state.op.empty() || Token::Match(tok->previous(), "[{,]") || Token::Match(tok->tokAt(-2), "%name% (")) {
834-
if (Token::Match(tok->tokAt(-1), "!!, { . %name% =|{")) {
834+
if (Token::Match(tok->tokAt(-1), "!!, { . %name% =|{") && !Token::simpleMatch(tok->tokAt(-1), "(")) {
835835
const int inArrayAssignment = state.inArrayAssignment;
836836
state.inArrayAssignment = 1;
837837
compileBinOp(tok, state, compileExpression);

test/testother.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3902,6 +3902,9 @@ class TestOther : public TestFixture {
39023902
"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\n"
39033903
"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\n",
39043904
errout_str());
3905+
3906+
check("void push(V& v) { v.push_back({ .x = 1 }); }"); // #14010
3907+
ASSERT_EQUALS("", errout_str());
39053908
}
39063909

39073910
void constParameterCallback() {

test/testtokenize.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ class TestTokenizer : public TestFixture {
403403
TEST_CASE(astvardecl);
404404
TEST_CASE(astnewscoped);
405405
TEST_CASE(astdecltypescope);
406+
TEST_CASE(astdesignatedinit);
406407

407408
TEST_CASE(startOfExecutableScope);
408409

@@ -7176,6 +7177,10 @@ class TestTokenizer : public TestFixture {
71767177
ASSERT_EQUALS("sizedecltypethism_P.(XSize::::{", testAst("size { decltype(this->m_P)::X::Size };"));
71777178
}
71787179

7180+
void astdesignatedinit() {
7181+
ASSERT_EQUALS("(( f ({ (= (. x) 1)))", testAst("f({ .x = 1 });", AstStyle::Z3));
7182+
}
7183+
71797184
#define isStartOfExecutableScope(offset, code) isStartOfExecutableScope_(offset, code, __FILE__, __LINE__)
71807185
template<size_t size>
71817186
bool isStartOfExecutableScope_(int offset, const char (&code)[size], const char* file, int line) {

0 commit comments

Comments
 (0)