From patchwork Tue Jun 7 15:12:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 99260 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 55549B6FC1 for ; Wed, 8 Jun 2011 01:12:54 +1000 (EST) Received: (qmail 29143 invoked by alias); 7 Jun 2011 15:12:52 -0000 Received: (qmail 29126 invoked by uid 22791); 7 Jun 2011 15:12:50 -0000 X-SWARE-Spam-Status: No, hits=-6.4 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; Tue, 07 Jun 2011 15:12:34 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p57FCX1Y019359 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 7 Jun 2011 11:12:34 -0400 Received: from [127.0.0.1] (ovpn-113-53.phx2.redhat.com [10.3.113.53]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p57FCX3G006736 for ; Tue, 7 Jun 2011 11:12:33 -0400 Message-ID: <4DEE3FE0.2010603@redhat.com> Date: Tue, 07 Jun 2011 11:12:32 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: gcc-patches List Subject: Re: C++ PATCH for c++/48780 (non-promotion of scoped enums) References: <4DD7357B.9050601@redhat.com> <4DD835A1.4040503@redhat.com> In-Reply-To: <4DD835A1.4040503@redhat.com> 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 bug report on IRC pointed out that we were giving the -Wabi warning in cases that don't affect the ABI at all, namely use of scoped enums in switch. So this patch limits the warning to the varargs case by catching scoped enums in perform_integral_promotions so that only callers that use the type_promotes_to hook directly will get the warning. Tested x86_64-pc-linux-gnu, applied to trunk and 4.6. commit 7ceaa2bef7e4e9599fc7cd67b58b39736dd35d85 Author: Jason Merrill Date: Mon Jun 6 17:35:18 2011 -0400 PR c++/48780 * typeck.c (perform_integral_promotions): Don't promote scoped enums. * call.c (convert_arg_to_ellipsis): Promote them here in old ABI. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 246fb6d..7019da9 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -5724,7 +5724,15 @@ convert_arg_to_ellipsis (tree arg) else if (NULLPTR_TYPE_P (arg_type)) arg = null_pointer_node; else if (INTEGRAL_OR_ENUMERATION_TYPE_P (arg_type)) - arg = perform_integral_promotions (arg); + { + if (SCOPED_ENUM_P (arg_type) && !abi_version_at_least (6)) + { + warning (OPT_Wabi, "scoped enum %qT will not promote to an " + "integral type in a future version of GCC", arg_type); + arg = cp_convert (ENUM_UNDERLYING_TYPE (arg_type), arg); + } + arg = perform_integral_promotions (arg); + } arg = require_complete_type (arg); arg_type = TREE_TYPE (arg); diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 2022f0f..6214452 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -1946,6 +1946,9 @@ perform_integral_promotions (tree expr) if (!type || TREE_CODE (type) != ENUMERAL_TYPE) type = TREE_TYPE (expr); gcc_assert (INTEGRAL_OR_ENUMERATION_TYPE_P (type)); + /* Scoped enums don't promote. */ + if (SCOPED_ENUM_P (type)) + return expr; promoted_type = type_promotes_to (type); if (type != promoted_type) expr = cp_convert (promoted_type, expr); diff --git a/gcc/testsuite/g++.dg/cpp0x/enum19.C b/gcc/testsuite/g++.dg/cpp0x/enum19.C new file mode 100644 index 0000000..acdd86c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/enum19.C @@ -0,0 +1,12 @@ +// We shouldn't give an ABI warning about promotion in switch. +// { dg-options "-std=c++0x -fabi-version=5 -Wabi" } + +enum class Foo { X }; +void test(Foo val) +{ + switch(val) + { + case Foo::X: + break; + } +};