public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/61343] New: [C++11] Missing default initialization for class with default constructor @ 2014-05-28 13:29 tejohnson at google dot com 2014-05-28 16:18 ` [Bug c++/61343] " redi at gcc dot gnu.org ` (4 more replies) 0 siblings, 5 replies; 6+ messages in thread From: tejohnson at google dot com @ 2014-05-28 13:29 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61343 Bug ID: 61343 Summary: [C++11] Missing default initialization for class with default constructor Product: gcc Version: 4.10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: tejohnson at google dot com The following test case does not call the default constructor when expected: ///////////////////////////// #include <iostream> struct Foo { int value; Foo() noexcept { std::cout << this << " constructed. Setting value to twelve.\n"; value = 12; } }; static thread_local Foo a{}; static thread_local Foo b; static __attribute__((noinline)) void UseA() { const int value = a.value; std::cout << "Value of A: " << value << "\n"; } static __attribute__((noinline)) void UseB() { const int value = b.value; std::cout << "Value of B: " << value << "\n"; } int main(int argc, char** argv) { // std::cout << "Address of A: " << &a << "\n"; // std::cout << "Address of B: " << &b << "\n"; UseA(); UseA(); UseB(); UseB(); UseA(); UseA(); return 0; } ////////////////////////// When compiled with the current trunk compiler it gives the output: > Value of A: 0 > Value of A: 0 > 0x7f2bc9150728 constructed. Setting value to twelve. > 0x7f2bc9150724 constructed. Setting value to twelve. > Value of B: 12 > Value of B: 12 > Value of A: 12 > Value of A: 12 I would expect something like: > 0x7ffa4bc63720 constructed. Setting value to twelve. > 0x7ffa4bc63724 constructed. Setting value to twelve. > Value of A: 12 > Value of A: 12 > Value of B: 12 > Value of B: 12 > Value of A: 12 > Value of A: 12 It appears as though the empty brace initialization for 'a', which should result in the user-defined default constructor being invoked, does not actually do so. Instead the object is zero-initialized until accessing 'b', which finally causes the default constructor for 'a' to be run as well. Google ref: b/15250505 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/61343] [C++11] Missing default initialization for class with default constructor 2014-05-28 13:29 [Bug c++/61343] New: [C++11] Missing default initialization for class with default constructor tejohnson at google dot com @ 2014-05-28 16:18 ` redi at gcc dot gnu.org 2014-06-05 17:31 ` jason at gcc dot gnu.org ` (3 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: redi at gcc dot gnu.org @ 2014-05-28 16:18 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61343 Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2014-05-28 Ever confirmed|0 |1 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/61343] [C++11] Missing default initialization for class with default constructor 2014-05-28 13:29 [Bug c++/61343] New: [C++11] Missing default initialization for class with default constructor tejohnson at google dot com 2014-05-28 16:18 ` [Bug c++/61343] " redi at gcc dot gnu.org @ 2014-06-05 17:31 ` jason at gcc dot gnu.org 2014-06-09 19:29 ` jason at gcc dot gnu.org ` (2 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: jason at gcc dot gnu.org @ 2014-06-05 17:31 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61343 --- Comment #1 from Jason Merrill <jason at gcc dot gnu.org> --- Author: jason Date: Thu Jun 5 17:30:51 2014 New Revision: 211284 URL: http://gcc.gnu.org/viewcvs?rev=211284&root=gcc&view=rev Log: PR c++/61343 * decl.c (check_initializer): Maybe clear DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P. Added: trunk/gcc/testsuite/g++.dg/tls/thread_local9.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/decl.c ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/61343] [C++11] Missing default initialization for class with default constructor 2014-05-28 13:29 [Bug c++/61343] New: [C++11] Missing default initialization for class with default constructor tejohnson at google dot com 2014-05-28 16:18 ` [Bug c++/61343] " redi at gcc dot gnu.org 2014-06-05 17:31 ` jason at gcc dot gnu.org @ 2014-06-09 19:29 ` jason at gcc dot gnu.org 2014-06-09 19:29 ` jason at gcc dot gnu.org 2014-06-11 13:45 ` tejohnson at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: jason at gcc dot gnu.org @ 2014-06-09 19:29 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61343 --- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> --- Author: jason Date: Mon Jun 9 19:29:17 2014 New Revision: 211386 URL: http://gcc.gnu.org/viewcvs?rev=211386&root=gcc&view=rev Log: PR c++/61343 * decl.c (check_initializer): Maybe clear DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P. Added: branches/gcc-4_9-branch/gcc/testsuite/g++.dg/tls/thread_local9.C Modified: branches/gcc-4_9-branch/gcc/cp/ChangeLog branches/gcc-4_9-branch/gcc/cp/decl.c ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/61343] [C++11] Missing default initialization for class with default constructor 2014-05-28 13:29 [Bug c++/61343] New: [C++11] Missing default initialization for class with default constructor tejohnson at google dot com ` (2 preceding siblings ...) 2014-06-09 19:29 ` jason at gcc dot gnu.org @ 2014-06-09 19:29 ` jason at gcc dot gnu.org 2014-06-11 13:45 ` tejohnson at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: jason at gcc dot gnu.org @ 2014-06-09 19:29 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61343 Jason Merrill <jason at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |jason at gcc dot gnu.org Resolution|--- |FIXED Assignee|unassigned at gcc dot gnu.org |jason at gcc dot gnu.org Target Milestone|--- |4.9.1 --- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> --- Fixed for 4.9.1. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/61343] [C++11] Missing default initialization for class with default constructor 2014-05-28 13:29 [Bug c++/61343] New: [C++11] Missing default initialization for class with default constructor tejohnson at google dot com ` (3 preceding siblings ...) 2014-06-09 19:29 ` jason at gcc dot gnu.org @ 2014-06-11 13:45 ` tejohnson at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: tejohnson at gcc dot gnu.org @ 2014-06-11 13:45 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61343 --- Comment #4 from tejohnson at gcc dot gnu.org --- Author: tejohnson Date: Wed Jun 11 13:45:00 2014 New Revision: 211466 URL: http://gcc.gnu.org/viewcvs?rev=211466&root=gcc&view=rev Log: Backport r211386 from gcc-4_9 (r211284 from trunk). Google ref b/15250505. 2014-06-04 Jason Merrill <jason@redhat.com> PR c++/61343 * decl.c (check_initializer): Maybe clear DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P. Added: branches/google/gcc-4_8/gcc/testsuite/g++.dg/tls/thread_local9.C Modified: branches/google/gcc-4_8/gcc/cp/decl.c ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-06-11 13:45 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-05-28 13:29 [Bug c++/61343] New: [C++11] Missing default initialization for class with default constructor tejohnson at google dot com 2014-05-28 16:18 ` [Bug c++/61343] " redi at gcc dot gnu.org 2014-06-05 17:31 ` jason at gcc dot gnu.org 2014-06-09 19:29 ` jason at gcc dot gnu.org 2014-06-09 19:29 ` jason at gcc dot gnu.org 2014-06-11 13:45 ` tejohnson 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).