From patchwork Mon Sep 6 04:47:24 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 63874 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 664C3B70EE for ; Mon, 6 Sep 2010 14:47:35 +1000 (EST) Received: (qmail 22241 invoked by alias); 6 Sep 2010 04:47:33 -0000 Received: (qmail 22231 invoked by uid 22791); 6 Sep 2010 04:47:32 -0000 X-SWARE-Spam-Status: No, hits=-6.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, 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; Mon, 06 Sep 2010 04:47:27 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o864lPQC024466 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 6 Sep 2010 00:47:26 -0400 Received: from [127.0.0.1] ([10.3.113.19]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o864lPxe005032 for ; Mon, 6 Sep 2010 00:47:25 -0400 Message-ID: <4C84725C.9070703@redhat.com> Date: Mon, 06 Sep 2010 00:47:24 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.12) Gecko/20100831 Lightning/1.0b1 Shredder/3.0.8pre MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH to fix Enum{} 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 The code for handling conversion of {} to scalar type was assuming that we could do an implicit conversion from integer 0 to any scalar type. But that's not true of enums. Tested x86_64-pc-linux-gnu, applied to trunk. commit 31436fc0666220ad0e4a05fdef4ad8335ce74d74 Author: Jason Merrill Date: Sun Sep 5 09:05:45 2010 -0400 * call.c (implicit_conversion): Fix value-init of enums. (convert_like_real): Likewise. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 36f5a55..54a711a 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -1457,7 +1457,7 @@ implicit_conversion (tree to, tree from, tree expr, bool c_cast_p, tree elt; if (nelts == 0) - elt = integer_zero_node; + elt = build_value_init (to, tf_none); else if (nelts == 1) elt = CONSTRUCTOR_ELT (expr, 0)->value; else @@ -5050,7 +5050,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, { int nelts = CONSTRUCTOR_NELTS (expr); if (nelts == 0) - expr = integer_zero_node; + expr = build_value_init (totype, tf_warning_or_error); else if (nelts == 1) expr = CONSTRUCTOR_ELT (expr, 0)->value; else diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist42.C b/gcc/testsuite/g++.dg/cpp0x/initlist42.C new file mode 100644 index 0000000..e63959d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist42.C @@ -0,0 +1,13 @@ +// { dg-options -std=c++0x } + +enum Unscoped { }; +enum class Scoped { }; + +Unscoped bar(Unscoped x) { return x; } +Scoped bar(Scoped x) { return x; } + +auto var1u = bar(Unscoped()); // OK +auto var1s = bar(Scoped()); // OK + +auto var2u = bar(Unscoped{}); // #1 Error, but should work +auto var2s = bar(Scoped{}); // #2 Error, but should work