From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7664 invoked by alias); 30 Mar 2012 20:30:04 -0000 Received: (qmail 7548 invoked by uid 22791); 30 Mar 2012 20:30:01 -0000 X-SWARE-Spam-Status: No, hits=-3.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 30 Mar 2012 20:29:48 +0000 From: "jyasskin at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/52796] New: [4.6/4.7 C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize Date: Fri, 30 Mar 2012 21:01:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jyasskin at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-03/txt/msg02703.txt.bz2 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(3) failed to initialize the list elements. $ cat test.cc #include #include template class Wrapper { public: #if WORK Wrapper() : t() { } #endif template Wrapper(Args&&... args) : t(args...) { } T t; }; int main() { __attribute__(aligned(alignof(Wrapper))) char space[sizeof(Wrapper)]; memset(space, '\xab', sizeof(space)); Wrapper*w = new(space) Wrapper; std::cout << (int)w->t << '\n'; w->~Wrapper(); memset(space, '\xab', sizeof(space)); w = new(space) Wrapper(); std::cout << (int)w->t << '\n'; w->~Wrapper(); memset(space, '\xab', sizeof(space)); w = new(space) Wrapper((int)'y'); std::cout << (int)w->t << '\n'; w->~Wrapper(); } $ 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::Wrapper<>(): 0x0000000000400a70 <+0>: push %rbp 0x0000000000400a71 <+1>: mov %rsp,%rbp 0x0000000000400a74 <+4>: mov %rdi,-0x8(%rbp) => 0x0000000000400a78 <+8>: pop %rbp 0x0000000000400a79 <+9>: retq