<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/76546>76546</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
False positives for -Wunsequenced
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Halalaluyafail3
</td>
</tr>
</table>
<pre>
Clang interprets the evaluation of initializers as being unsequenced, which is incorrect.
For example the code here https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1729.htm in point B:
```c
#include <stdio.h>
#define ONE_INIT '0' + i++ % 3
#define INITIALIZERS [2] = ONE_INIT, [1] = ONE_INIT, [0] = ONE_INIT
int main()
{
int i = 0;
char x[4] = { INITIALIZERS }; // case 1
puts(x);
puts((char [4]){ INITIALIZERS }); // case 2
puts((char [4]){ INITIALIZERS } + i % 2); // case 3
}
```
A warning is generated for case 3, which is correct; but no `-Wunsequenced` warnings should be generated for cases 1 or 2 which have defined behavior.
I found issue #32412 which references the same problem, and the conclusion reached there doesn't really make much sense.
> The evaluations of the initialization list expressions are indeterminately sequenced with respect to
> one another and thus the order in which any side effects occur is unspecified.
Section 6.7.9 "Initialization" Paragraph 23 ISO 9899:2018
> Evaluations A and B are indeterminately sequenced when A is
> sequenced either before or after B, but it is unspecified which.
Section 5.1.2.3 "Program execution" Paragraph 3 ISO 9899:2018
The evaluations of each initializer are sequenced and are in unspecified order, but this doesn't mean that they are unsequenced.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVV-P4jYQ_zTmZbRRMk4CeeABdhcVqbo79U6q1JfKsSfE18RObWdZ-ukrJ7DA3raVKhAW45nfzG_-WXivD4ZozYotK54WYgytdeufRBc_40k0Qnd8UVt1Wj92whxAm0BucBQ8hJaAXkQ3iqCtAduANjpo0em_yHkQHmrS5gCj8fTnSEaSYvgIx1bLFrQHbaR1jmRIWPrE0s38u7MO6FX0Q0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