From patchwork Tue Apr 3 22:49:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 150567 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 54C80B6FBC for ; Wed, 4 Apr 2012 08:50:01 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1334098203; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=UDUaOkd mRfC7wqOwYBU+OtqVHdg=; b=EiU848tL19pKpLt3z5P/yCDBHDQLHyIs3ZcMTvJ 0MVHCwFRchHySoVIyvPWGAhOwOAeUSG0LZl3ujOZJeJ6KXUNhcA7e/CS9hIfBnhg DYyTlaa15sRLPlr1zeGPXZ8MyA1e4zfzn+n3IwNivdRtZLJoTeRc9vjO9CBG9u4F Byp0= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=VY4sRU5I6bFvaxxoIlDsOKYOjr+kSFb8kH35jFzViDb1cEu6VE916Mni4PP0t3 cPkZYiyAcwRmYZu1G4dVyL2dPygR7LBkRON6u6XU3sEMHZUgUcR3vf6hkDerR1Ze pAwjDXSp+VyXVeKH9OYXBzCeX1FBdqxU1Lj0E/RzxlAck=; Received: (qmail 7280 invoked by alias); 3 Apr 2012 22:49:57 -0000 Received: (qmail 7265 invoked by uid 22791); 3 Apr 2012 22:49:56 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 03 Apr 2012 22:49:40 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q33Mndxb018080 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 3 Apr 2012 18:49:39 -0400 Received: from [10.3.113.125] (ovpn-113-125.phx2.redhat.com [10.3.113.125]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q33MncMa012101 for ; Tue, 3 Apr 2012 18:49:39 -0400 Message-ID: <4F7B7E82.9090808@redhat.com> Date: Tue, 03 Apr 2012 18:49:38 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20120329 Thunderbird/11.0.1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/52796 (missed value-initialization with variadic templates) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org A parenthesized initializer containing a pack expansion that expands to 0 elements is treated as value-initialization. We were handling that properly for variable initializers, but not for mem-initializers in constructors. Tested x86_64-pc-linux-gnu, applying to trunk, 4.7 and 4.6. commit 58c6706693964e81e846905cdd747a4aec015d09 Author: Jason Merrill Date: Tue Apr 3 15:31:39 2012 -0400 PR c++/52796 * pt.c (tsubst_initializer_list): A pack expansion with no elements means value-initialization. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index aabe477..03acd5b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -19470,6 +19470,7 @@ tsubst_initializer_list (tree t, tree argvec) } else { + tree tmp; decl = tsubst_copy (TREE_PURPOSE (t), argvec, tf_warning_or_error, NULL_TREE); @@ -19478,10 +19479,17 @@ tsubst_initializer_list (tree t, tree argvec) in_base_initializer = 1; init = TREE_VALUE (t); + tmp = init; if (init != void_type_node) init = tsubst_expr (init, argvec, tf_warning_or_error, NULL_TREE, /*integral_constant_expression_p=*/false); + if (init == NULL_TREE && tmp != NULL_TREE) + /* If we had an initializer but it instantiated to nothing, + value-initialize the object. This will only occur when + the initializer was a pack expansion where the parameter + packs used in that expansion were of length zero. */ + init = void_type_node; in_base_initializer = 0; } diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic-value1.C b/gcc/testsuite/g++.dg/cpp0x/variadic-value1.C new file mode 100644 index 0000000..179919a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/variadic-value1.C @@ -0,0 +1,24 @@ +// PR c++/52796 +// { dg-do run { target c++11 } } + +inline void *operator new(__SIZE_TYPE__ s, void *p) { return p; } + +struct A +{ + int i; + template + A(Ts&&... ts): i(ts...) { } +}; + +static union { + unsigned char c[sizeof(A)]; + int i; +}; + +int main() +{ + i = 0xdeadbeef; + new(c) A; + if (i != 0) + __builtin_abort(); +}