From patchwork Fri Aug 5 19:18:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 108715 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 5D14FB6F76 for ; Sat, 6 Aug 2011 05:18:49 +1000 (EST) Received: (qmail 14028 invoked by alias); 5 Aug 2011 19:18:47 -0000 Received: (qmail 14020 invoked by uid 22791); 5 Aug 2011 19:18:47 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS 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; Fri, 05 Aug 2011 19:18:32 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p75JIUUD025227 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 5 Aug 2011 15:18:30 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p75JITNL029423 for ; Fri, 5 Aug 2011 15:18:30 -0400 Received: from [0.0.0.0] (ovpn-113-87.phx2.redhat.com [10.3.113.87]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p75JIS3U004890 for ; Fri, 5 Aug 2011 15:18:29 -0400 Message-ID: <4E3C4204.805@redhat.com> Date: Fri, 05 Aug 2011 15:18:28 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:5.0) Gecko/20110719 Thunderbird/5.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCHes for c++/47453 (rejecting ({...}) for non-class types) 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 DR 1214 established that an initializer of the form ({something}) is only valid for an object of class type. This patch implements that, though I've only made it a pedwarn as there is some uncertainty about whether this is actually what we want. I've also split the patch into two to make it easier to revert if that turns out not to be the case; the first part is a cleanup which is correct either way. Tested x86_64-pc-linux-gnu, applying to trunk. commit ffa8f76324849e367023a06b0ae663a798db64ad Author: Jason Merrill Date: Thu Aug 4 17:32:32 2011 -0400 PR c++/47453 * typeck.c (build_x_compound_expr_from_list): Also complain about ({...}). diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index f53deb9..a1f6761 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -5470,6 +5470,16 @@ build_x_compound_expr_from_list (tree list, expr_list_kind exp, { tree expr = TREE_VALUE (list); + if (BRACE_ENCLOSED_INITIALIZER_P (expr) + && !CONSTRUCTOR_IS_DIRECT_INIT (expr)) + { + if (complain & tf_error) + pedwarn (EXPR_LOC_OR_HERE (expr), 0, "list-initializer for " + "non-class type must not be parenthesized"); + else + return error_mark_node; + } + if (TREE_CHAIN (list)) { if (complain & tf_error) diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist13.C b/gcc/testsuite/g++.dg/cpp0x/initlist13.C index 9ed6c74..bc5ee2c 100644 --- a/gcc/testsuite/g++.dg/cpp0x/initlist13.C +++ b/gcc/testsuite/g++.dg/cpp0x/initlist13.C @@ -4,5 +4,5 @@ #include -__complex__ int i ({0}); -std::complex i2 ({0}); +__complex__ int i {0}; +std::complex i2 {0}; diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist50.C b/gcc/testsuite/g++.dg/cpp0x/initlist50.C index ef4e72c..5cb23e2 100644 --- a/gcc/testsuite/g++.dg/cpp0x/initlist50.C +++ b/gcc/testsuite/g++.dg/cpp0x/initlist50.C @@ -8,7 +8,7 @@ struct A2 { template struct B { T ar[1]; - B(T t):ar({t}) {} + B(T t):ar{t} {} }; int main(){ diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist56.C b/gcc/testsuite/g++.dg/cpp0x/initlist56.C new file mode 100644 index 0000000..862b41b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist56.C @@ -0,0 +1,37 @@ +// PR c++/47453 +// { dg-options "-std=c++0x -pedantic-errors" } + +// invalid +int a({0}); // { dg-error "" } + +// invalid +int const &b({0}); // { dg-error "" } + +// invalid +struct A1 { int a[2]; A1(); }; +A1::A1():a({1, 2}) { } // { dg-error "" } + +struct A { explicit A(int, int); A(int, long); }; + +// invalid +A c({1, 2}); // { dg-error "" } + +// valid (by copy constructor). +A d({1, 2L}); + +// valid +A e{1, 2}; + +#include + +struct B { + template + B(std::initializer_list, T ...); +}; + +// invalid (the first phase only considers init-list ctors) +// (for the second phase, no constructor is viable) +B f{1, 2, 3}; // { dg-error "" } + +// valid (T deduced to <>). +B g({1, 2, 3});