Issue 76546
Summary False positives for -Wunsequenced
Labels new issue
Assignees
Reporter Halalaluyafail3
    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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to