public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/52796] New: [4.6/4.7 C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize @ 2012-03-30 21:01 jyasskin at gcc dot gnu.org 2012-03-30 21:22 ` [Bug c++/52796] " jyasskin at gcc dot gnu.org ` (8 more replies) 0 siblings, 9 replies; 10+ messages in thread From: jyasskin at gcc dot gnu.org @ 2012-03-30 21:01 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52796 Bug #: 52796 Summary: [4.6/4.7 C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize Classification: Unclassified Product: gcc Version: 4.7.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: jyasskin@gcc.gnu.org The following program attempts to initialize a 'char' member using a variadic parameter pack. With length 0, the initialization doesn't happen, leaving the original value of the memory in the field. I originally noticed this in gcc-4.6 when std::list<char>(3) failed to initialize the list elements. $ cat test.cc #include <memory.h> #include <iostream> template<typename T> class Wrapper { public: #if WORK Wrapper() : t() { } #endif template<typename ...Args> Wrapper(Args&&... args) : t(args...) { } T t; }; int main() { __attribute__(aligned(alignof(Wrapper<char>))) char space[sizeof(Wrapper<char>)]; memset(space, '\xab', sizeof(space)); Wrapper<char>*w = new(space) Wrapper<char>; std::cout << (int)w->t << '\n'; w->~Wrapper<char>(); memset(space, '\xab', sizeof(space)); w = new(space) Wrapper<char>(); std::cout << (int)w->t << '\n'; w->~Wrapper<char>(); memset(space, '\xab', sizeof(space)); w = new(space) Wrapper<char>((int)'y'); std::cout << (int)w->t << '\n'; w->~Wrapper<char>(); } $ g++-4.7pre --version g++-4.7pre (GCC) 4.7.1 20120330 (prerelease) ... $ g++-4.7pre -Wall -std=c++11 test.cc -g3 -o test && ./test -85 0 121 Disassembling with gdb shows: Dump of assembler code for function Wrapper<char>::Wrapper<>(): 0x0000000000400a70 <+0>: push %rbp 0x0000000000400a71 <+1>: mov %rsp,%rbp 0x0000000000400a74 <+4>: mov %rdi,-0x8(%rbp) => 0x0000000000400a78 <+8>: pop %rbp 0x0000000000400a79 <+9>: retq ^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/52796] [4.6/4.7 C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize 2012-03-30 21:01 [Bug c++/52796] New: [4.6/4.7 C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize jyasskin at gcc dot gnu.org @ 2012-03-30 21:22 ` jyasskin at gcc dot gnu.org 2012-03-30 21:54 ` [Bug c++/52796] [4.6/4.7/4.8 " jyasskin at gcc dot gnu.org ` (7 subsequent siblings) 8 siblings, 0 replies; 10+ messages in thread From: jyasskin at gcc dot gnu.org @ 2012-03-30 21:22 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52796 --- Comment #1 from Jeffrey Yasskin <jyasskin at gcc dot gnu.org> 2012-03-30 21:18:09 UTC --- Created attachment 27050 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27050 Test file demonstrating improvement from 4.6->4.7 The attached 46_vs_47.cc shows that gcc-4.7 calls the default constructor for pack uses like new Type(args...), while gcc-4.6 didn't. So 4.7 doesn't have the std::list bug. I tested this with valgrind-3.6.0: $ g++-4.6.x --version g++-4.6.x (GCC) 4.6.4 20120330 (prerelease) $ g++-4.6.x -Wall -std=c++0x 46_vs_47.cc -g3 -o test && /usr/bin/valgrind ./test ... ==15840== Conditional jump or move depends on uninitialised value(s) ==15840== at 0x4EB8074: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const (locale_facets.tcc:872) ==15840== by 0x4EB8395: std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::do_put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const (locale_facets.h:2475) ==15840== by 0x4EC33CC: std::ostream& std::ostream::_M_insert<long>(long) (locale_facets.h:2336) ==15840== by 0x400BF7: void check_init<>() (46_vs_47.cc:19) ==15840== by 0x400AC1: main (46_vs_47.cc:24) ... 0 3 ==15840== Conditional jump or move depends on uninitialised value(s) ==15840== at 0x4EB8074: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const (locale_facets.tcc:872) ==15840== by 0x4EB8395: std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::do_put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const (locale_facets.h:2475) ==15840== by 0x4EC33CC: std::ostream& std::ostream::_M_insert<long>(long) (locale_facets.h:2336) ==15840== by 0x400B03: main (46_vs_47.cc:27) ... 0 $ g++-4.7pre --version g++-4.7pre (GCC) 4.7.1 20120330 (prerelease) $ g++-4.7pre -Wall -std=c++11 test.cc -g3 -o test && /usr/bin/valgrind ./test ==8931== Memcheck, a memory error detector ==8931== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==8931== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info ==8931== Command: ./test ==8931== 0 3 0 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/52796] [4.6/4.7/4.8 C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize 2012-03-30 21:01 [Bug c++/52796] New: [4.6/4.7 C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize jyasskin at gcc dot gnu.org 2012-03-30 21:22 ` [Bug c++/52796] " jyasskin at gcc dot gnu.org @ 2012-03-30 21:54 ` jyasskin at gcc dot gnu.org 2012-04-03 14:45 ` [Bug c++/52796] [C++11] " jason at gcc dot gnu.org ` (6 subsequent siblings) 8 siblings, 0 replies; 10+ messages in thread From: jyasskin at gcc dot gnu.org @ 2012-03-30 21:54 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52796 Jeffrey Yasskin <jyasskin at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|[4.6/4.7 C++11] |[4.6/4.7/4.8 C++11] |Initialization of primitive |Initialization of primitive |object with 0-length |object with 0-length |parameter pack fails to |parameter pack fails to |value-initialize |value-initialize --- Comment #2 from Jeffrey Yasskin <jyasskin at gcc dot gnu.org> 2012-03-30 21:22:30 UTC --- And 4.8.0 20120330 matches 4.7's behavior for both test cases. ^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/52796] [C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize 2012-03-30 21:01 [Bug c++/52796] New: [4.6/4.7 C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize jyasskin at gcc dot gnu.org 2012-03-30 21:22 ` [Bug c++/52796] " jyasskin at gcc dot gnu.org 2012-03-30 21:54 ` [Bug c++/52796] [4.6/4.7/4.8 " jyasskin at gcc dot gnu.org @ 2012-04-03 14:45 ` jason at gcc dot gnu.org 2012-04-03 22:51 ` jason at gcc dot gnu.org ` (5 subsequent siblings) 8 siblings, 0 replies; 10+ messages in thread From: jason at gcc dot gnu.org @ 2012-04-03 14:45 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52796 Jason Merrill <jason at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |ASSIGNED Last reconfirmed| |2012-04-03 CC| |jason at gcc dot gnu.org AssignedTo|unassigned at gcc dot |jason at gcc dot gnu.org |gnu.org | Ever Confirmed|0 |1 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/52796] [C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize 2012-03-30 21:01 [Bug c++/52796] New: [4.6/4.7 C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize jyasskin at gcc dot gnu.org ` (2 preceding siblings ...) 2012-04-03 14:45 ` [Bug c++/52796] [C++11] " jason at gcc dot gnu.org @ 2012-04-03 22:51 ` jason at gcc dot gnu.org 2012-04-03 23:38 ` jason at gcc dot gnu.org ` (4 subsequent siblings) 8 siblings, 0 replies; 10+ messages in thread From: jason at gcc dot gnu.org @ 2012-04-03 22:51 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52796 --- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2012-04-03 22:51:14 UTC --- Author: jason Date: Tue Apr 3 22:51:08 2012 New Revision: 186120 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186120 Log: PR c++/52796 * pt.c (tsubst_initializer_list): A pack expansion with no elements means value-initialization. Added: branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/variadic-value1.C Modified: branches/gcc-4_6-branch/gcc/cp/ChangeLog branches/gcc-4_6-branch/gcc/cp/pt.c branches/gcc-4_6-branch/gcc/testsuite/ChangeLog ^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/52796] [C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize 2012-03-30 21:01 [Bug c++/52796] New: [4.6/4.7 C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize jyasskin at gcc dot gnu.org ` (3 preceding siblings ...) 2012-04-03 22:51 ` jason at gcc dot gnu.org @ 2012-04-03 23:38 ` jason at gcc dot gnu.org 2012-04-03 23:38 ` jason at gcc dot gnu.org ` (3 subsequent siblings) 8 siblings, 0 replies; 10+ messages in thread From: jason at gcc dot gnu.org @ 2012-04-03 23:38 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52796 --- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> 2012-04-03 23:38:25 UTC --- Author: jason Date: Tue Apr 3 23:38:21 2012 New Revision: 186122 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186122 Log: PR c++/52796 * pt.c (tsubst_initializer_list): A pack expansion with no elements means value-initialization. Added: trunk/gcc/testsuite/g++.dg/cpp0x/variadic-value1.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/pt.c trunk/gcc/testsuite/ChangeLog ^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/52796] [C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize 2012-03-30 21:01 [Bug c++/52796] New: [4.6/4.7 C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize jyasskin at gcc dot gnu.org ` (4 preceding siblings ...) 2012-04-03 23:38 ` jason at gcc dot gnu.org @ 2012-04-03 23:38 ` jason at gcc dot gnu.org 2012-04-04 1:39 ` jason at gcc dot gnu.org ` (2 subsequent siblings) 8 siblings, 0 replies; 10+ messages in thread From: jason at gcc dot gnu.org @ 2012-04-03 23:38 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52796 --- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2012-04-03 23:37:16 UTC --- Author: jason Date: Tue Apr 3 23:37:11 2012 New Revision: 186121 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186121 Log: PR c++/52796 * pt.c (tsubst_initializer_list): A pack expansion with no elements means value-initialization. Added: branches/gcc-4_7-branch/gcc/testsuite/g++.dg/cpp0x/variadic-value1.C Modified: branches/gcc-4_7-branch/gcc/cp/ChangeLog branches/gcc-4_7-branch/gcc/cp/pt.c branches/gcc-4_7-branch/gcc/testsuite/ChangeLog ^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/52796] [C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize 2012-03-30 21:01 [Bug c++/52796] New: [4.6/4.7 C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize jyasskin at gcc dot gnu.org ` (5 preceding siblings ...) 2012-04-03 23:38 ` jason at gcc dot gnu.org @ 2012-04-04 1:39 ` jason at gcc dot gnu.org 2012-04-05 15:07 ` bkoz at gcc dot gnu.org 2012-05-23 21:43 ` michaelh at gcc dot gnu.org 8 siblings, 0 replies; 10+ messages in thread From: jason at gcc dot gnu.org @ 2012-04-04 1:39 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52796 Jason Merrill <jason at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |RESOLVED Resolution| |FIXED Target Milestone|--- |4.6.4 --- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> 2012-04-04 01:38:20 UTC --- Fixed for 4.6.4, 4.7.1 and 4.8. ^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/52796] [C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize 2012-03-30 21:01 [Bug c++/52796] New: [4.6/4.7 C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize jyasskin at gcc dot gnu.org ` (6 preceding siblings ...) 2012-04-04 1:39 ` jason at gcc dot gnu.org @ 2012-04-05 15:07 ` bkoz at gcc dot gnu.org 2012-05-23 21:43 ` michaelh at gcc dot gnu.org 8 siblings, 0 replies; 10+ messages in thread From: bkoz at gcc dot gnu.org @ 2012-04-05 15:07 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52796 Benjamin Kosnik <bkoz at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bkoz at gcc dot gnu.org --- Comment #7 from Benjamin Kosnik <bkoz at gcc dot gnu.org> 2012-04-05 15:06:21 UTC --- Nice work on this Jeffrey. ^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/52796] [C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize 2012-03-30 21:01 [Bug c++/52796] New: [4.6/4.7 C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize jyasskin at gcc dot gnu.org ` (7 preceding siblings ...) 2012-04-05 15:07 ` bkoz at gcc dot gnu.org @ 2012-05-23 21:43 ` michaelh at gcc dot gnu.org 8 siblings, 0 replies; 10+ messages in thread From: michaelh at gcc dot gnu.org @ 2012-05-23 21:43 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52796 --- Comment #8 from michaelh at gcc dot gnu.org 2012-05-23 21:34:54 UTC --- Author: michaelh Date: Wed May 23 21:34:50 2012 New Revision: 187816 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187816 Log: Fix the PR entry in the ChangeLog. Should be: 2012-05-23 Michael Hope <michael.hope@linaro.org> PR c++/52796 * g++.dg/cpp0x/variadic-value1.C: Change selector for explicit options. Modified: branches/gcc-4_6-branch/gcc/testsuite/ChangeLog ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2012-05-23 21:35 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-03-30 21:01 [Bug c++/52796] New: [4.6/4.7 C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize jyasskin at gcc dot gnu.org 2012-03-30 21:22 ` [Bug c++/52796] " jyasskin at gcc dot gnu.org 2012-03-30 21:54 ` [Bug c++/52796] [4.6/4.7/4.8 " jyasskin at gcc dot gnu.org 2012-04-03 14:45 ` [Bug c++/52796] [C++11] " jason at gcc dot gnu.org 2012-04-03 22:51 ` jason at gcc dot gnu.org 2012-04-03 23:38 ` jason at gcc dot gnu.org 2012-04-03 23:38 ` jason at gcc dot gnu.org 2012-04-04 1:39 ` jason at gcc dot gnu.org 2012-04-05 15:07 ` bkoz at gcc dot gnu.org 2012-05-23 21:43 ` michaelh 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).