Skip to content

fix #14010: False constParameterReference ignoring call with designated-initializer & #14018: Invalid AST for function call with designated initializer #7673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ static void compileTerm(Token *&tok, AST_state& state)
} else if ((state.cpp && iscpp11init(tok)) || Token::simpleMatch(tok->previous(), "] {")) {
Token *const end = tok->link();
if (state.op.empty() || Token::Match(tok->previous(), "[{,]") || Token::Match(tok->tokAt(-2), "%name% (")) {
if (Token::Match(tok->tokAt(-1), "!!, { . %name% =|{")) {
if (Token::Match(tok->tokAt(-1), "!!, { . %name% =|{") && !Token::simpleMatch(tok->tokAt(-1), "(")) {
const int inArrayAssignment = state.inArrayAssignment;
state.inArrayAssignment = 1;
compileBinOp(tok, state, compileExpression);
Expand Down
3 changes: 3 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3902,6 +3902,9 @@ class TestOther : public TestFixture {
"[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\n"
"[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\n",
errout_str());

check("void push(V& v) { v.push_back({ .x = 1 }); }"); // #14010
ASSERT_EQUALS("", errout_str());
}

void constParameterCallback() {
Expand Down
5 changes: 5 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ class TestTokenizer : public TestFixture {
TEST_CASE(astvardecl);
TEST_CASE(astnewscoped);
TEST_CASE(astdecltypescope);
TEST_CASE(astdesignatedinit);

TEST_CASE(startOfExecutableScope);

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

void astdesignatedinit() {
ASSERT_EQUALS("(( f ({ (= (. x) 1)))", testAst("f({ .x = 1 });", AstStyle::Z3));
}

#define isStartOfExecutableScope(offset, code) isStartOfExecutableScope_(offset, code, __FILE__, __LINE__)
template<size_t size>
bool isStartOfExecutableScope_(int offset, const char (&code)[size], const char* file, int line) {
Expand Down