public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54399] New: Invalid partial change from dynamic to static initialization
@ 2012-08-29 1:25 rafael.espindola at gmail dot com
2021-08-11 23:32 ` [Bug c++/54399] " pinskia at gcc dot gnu.org
2021-08-11 23:34 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: rafael.espindola at gmail dot com @ 2012-08-29 1:25 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54399
Bug #: 54399
Summary: Invalid partial change from dynamic to static
initialization
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: rafael.espindola@gmail.com
I initially thought that this was a missed optimization in llvm
(http://llvm.org/pr13677), but Richard Smith convinced me this actually a bug
in gcc.
$ cat test1.cpp
struct foo {
int a;
int b;
int c;
int d;
int e;
};
int zed();
int x = zed();
foo bar = {x, 1, 2, 3, 4};
$ cat test2.cpp
#include <stdio.h>
struct foo {
int a;
int b;
int c;
int d;
int e;
};
extern foo bar;
int zed() { return bar.d; }
int main(void) {
printf("%d\n", bar.a);
return 0;
}
With gcc:
$ ~/gcc/build/gcc/xgcc -std=c++11 -B ~/gcc/build/gcc -c test1.cpp
$ ~/gcc/build/gcc/xgcc -std=c++11 -B ~/gcc/build/gcc -c test2.cpp
$ g++ test1.o test2.o -o t
$ ./t
3
and with clang:
$ clang test1.cpp test2.cpp -o t
[espindola@desktop llvm]$ ./t
0
If I understand Richard's argument correctly, the program must print 0 because
* from [basic.start.init] p2 both x and bar get dynamic initializations. In
that case x is initialized first and zed will see bar zero initialized.
* from p3, we can convert a variable to static initialization, but not part of
it. The possibilities are:
1) Only x is converted to static initialization. x should be static
initialized to 0. When bar is dynamic initialized it will be initialized to {0,
1, 2, 3, 4}.
2) Only bar is converted to static initialization. It should still be
initialized to {0, 1, 2, 3, 4}. In this case x is dynamically initialized to 3.
3) Both x and bar are converted to static initialization. In this case x is 0
and bar is {0, 1, 2, 3, 4}.
The output produced by gcc doesn't match any of the possibilities provided by
the standard.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/54399] Invalid partial change from dynamic to static initialization
2012-08-29 1:25 [Bug c++/54399] New: Invalid partial change from dynamic to static initialization rafael.espindola at gmail dot com
@ 2021-08-11 23:32 ` pinskia at gcc dot gnu.org
2021-08-11 23:34 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-11 23:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54399
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Last reconfirmed| |2021-08-11
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/54399] Invalid partial change from dynamic to static initialization
2012-08-29 1:25 [Bug c++/54399] New: Invalid partial change from dynamic to static initialization rafael.espindola at gmail dot com
2021-08-11 23:32 ` [Bug c++/54399] " pinskia at gcc dot gnu.org
@ 2021-08-11 23:34 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-11 23:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54399
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note ICC and GCC are the same here.
MSVC and clang are the same here.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-08-11 23:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-29 1:25 [Bug c++/54399] New: Invalid partial change from dynamic to static initialization rafael.espindola at gmail dot com
2021-08-11 23:32 ` [Bug c++/54399] " pinskia at gcc dot gnu.org
2021-08-11 23:34 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).