[Bug c/106853] New: compound literal storage duration
marcelgcc at firemail dot eu
gcc-bugzilla@gcc.gnu.org
Tue Sep 6 14:17:13 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106853
Bug ID: 106853
Summary: compound literal storage duration
Product: gcc
Version: 11.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: marcelgcc at firemail dot eu
Target Milestone: ---
According to the C Standard a compound literal has automatic storage duration.
Please, consider the following code. Note it's C code NOT C++:
% cat test.c
#include <stdio.h>
struct ab {
int a, b;
} *p1, *p2;
int set_p1(struct ab *ab) {
p1 = ab;
return 0;
}
int set_p2(struct ab *ab) {
p2 = ab;
return 0;
}
int main() {
if (0 != set_p1(&(struct ab){42, 42})) {
return 1;
}
set_p2(&(struct ab){46, 46});
printf("%d, %d\n", p1->a, p1->b);
printf("%d, %d\n", p2->a, p2->b);
return 0;
}
/*EOF*/
# Expected Output:
% clang-15 -O1 test.c && ./a.out
42, 42
46, 46
#####GCC#####
% gcc-11 -O1 test.c && ./a.out
0, 0
46, 46
% gcc-11 test.c && ./a.out
42, 42
46, 46
% gcc-12 test.c && ./a.out
46, 46
46, 46
% gcc-12 -O1 test.c && ./a.out
-760366272, 32718
46, 46
% gcc-11 --version
gcc (Debian 11.3.0-5) 11.3.0
% gcc-12 --version
gcc (GCC) 12.2.0
More information about the Gcc-bugs
mailing list