Skip to content

Commit d766098

Browse files
authored
Fix #14431: FP unknownEvaluationOrder with designated initializers (#8180)
1 parent 23adf76 commit d766098

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/checkother.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3794,6 +3794,8 @@ void CheckOther::checkEvaluationOrder()
37943794
continue;
37953795
if (!tok->astOperand1())
37963796
continue;
3797+
if (isDesignatedInitializer(tok->astOperand1()))
3798+
continue;
37973799
for (const Token *tok2 = tok;; tok2 = tok2->astParent()) {
37983800
// If ast parent is a sequence point then break
37993801
const Token * const parent = tok2->astParent();

test/testother.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11935,9 +11935,9 @@ class TestOther : public TestFixture {
1193511935
// TODO: only used in a single place
1193611936
#define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)
1193711937
template<size_t size>
11938-
void checkCustomSettings_(const char* file, int line, const char (&code)[size], const Settings& settings) {
11938+
void checkCustomSettings_(const char* file, int line, const char (&code)[size], const Settings& settings, bool cpp = true) {
1193911939
// Tokenize..
11940-
SimpleTokenizer tokenizer(settings, *this);
11940+
SimpleTokenizer tokenizer(settings, *this, cpp);
1194111941
ASSERT_LOC(tokenizer.tokenize(code), file, line);
1194211942

1194311943
// Check..
@@ -12010,6 +12010,12 @@ class TestOther : public TestFixture {
1201012010
" i = i++ + 2;\n"
1201112011
"}", settings11);
1201212012
ASSERT_EQUALS("[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str());
12013+
12014+
// #14431
12015+
checkCustomSettings("int f(void) {\n"
12016+
" struct baz baz = {.bar = {.foo = {.foo = 1}}};\n"
12017+
"}\n", settings0, false);
12018+
ASSERT_EQUALS("", errout_str());
1201312019
}
1201412020

1201512021
void testEvaluationOrderSelfAssignment() {

0 commit comments

Comments
 (0)