From patchwork Sat May 21 21:58:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 96713 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 E29C3B71B7 for ; Sun, 22 May 2011 07:59:14 +1000 (EST) Received: (qmail 13144 invoked by alias); 21 May 2011 21:59:13 -0000 Received: (qmail 13135 invoked by uid 22791); 21 May 2011 21:59:13 -0000 X-SWARE-Spam-Status: No, hits=-6.3 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; Sat, 21 May 2011 21:58:59 +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.14.4/8.14.4) with ESMTP id p4LLww9v029757 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 21 May 2011 17:58:58 -0400 Received: from [127.0.0.1] ([10.3.113.3]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p4LLww8g026908 for ; Sat, 21 May 2011 17:58:58 -0400 Message-ID: <4DD835A1.4040503@redhat.com> Date: Sat, 21 May 2011 17:58:57 -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> In-Reply-To: <4DD7357B.9050601@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 After I sent out that patch I realized that I was missing documentation and -Wabi bits, so this patch adds them. Tested x86_64-pc-linux-gnu, applied to trunk. New -Wabi warning also applied to 4.6. commit 3cd4d2ba12597289a7c3aa2bab8a09b5c0ca82f8 Author: Jason Merrill Date: Fri May 20 18:32:32 2011 -0400 PR c++/48780 * cvt.c (type_promotes_to): Don't promote scoped enums. diff --git a/gcc/common.opt b/gcc/common.opt index ebc2ba7..492d25e 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -759,6 +759,9 @@ Driver Undocumented ; function parameters used in other parameters and the return type. ; First selectable in G++ 4.6. ; +; 6: The version of the ABI that doesn't promote scoped enums to int. +; First selectable in G++ 4.7. +; ; Additional positive integers will be assigned as new versions of ; the ABI become the default version of the ABI. fabi-version= diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index db4ea46..e5d5361 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -1616,6 +1616,10 @@ type_promotes_to (tree type) if (TREE_CODE (type) == BOOLEAN_TYPE) type = integer_type_node; + /* scoped enums don't promote. */ + else if (SCOPED_ENUM_P (type) && abi_version_at_least (6)) + ; + /* Normally convert enums to int, but convert wide enums to something wider. */ else if (TREE_CODE (type) == ENUMERAL_TYPE @@ -1626,6 +1630,9 @@ type_promotes_to (tree type) int precision = MAX (TYPE_PRECISION (type), TYPE_PRECISION (integer_type_node)); tree totype = c_common_type_for_size (precision, 0); + if (SCOPED_ENUM_P (type)) + warning (OPT_Wabi, "scoped enum %qT will not promote to an integral " + "type in a future version of GCC", type); if (TREE_CODE (type) == ENUMERAL_TYPE) type = ENUM_UNDERLYING_TYPE (type); if (TYPE_UNSIGNED (type) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 46c0a70..7de8fd0 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1839,6 +1839,8 @@ Version 5 corrects the mangling of attribute const/volatile on function pointer types, decltype of a plain decl, and use of a function parameter in the declaration of another parameter. +Version 6 corrects the promotion behavior of C++0x scoped enums. + See also @option{-Wabi}. @item -fno-access-control diff --git a/gcc/testsuite/g++.dg/cpp0x/enum12.C b/gcc/testsuite/g++.dg/cpp0x/enum12.C new file mode 100644 index 0000000..b2ec919 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/enum12.C @@ -0,0 +1,18 @@ +// PR c++/48780 +// { dg-options "-std=c++0x -fabi-version=0" } + +typedef __builtin_va_list __gnuc_va_list; +typedef __gnuc_va_list va_list; + +enum struct A : short { X }; + +void foo(int x, ...) { + va_list vl; + __builtin_va_start(vl, x); + enum A t = __builtin_va_arg(vl, enum A); + __builtin_va_end(vl); +} + +int main() { + foo(0, A::X); +} diff --git a/gcc/testsuite/g++.dg/cpp0x/enum13.C b/gcc/testsuite/g++.dg/cpp0x/enum13.C new file mode 100644 index 0000000..ec02d3b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/enum13.C @@ -0,0 +1,20 @@ +// PR c++/48780 +// { dg-options "-std=c++0x -fabi-version=5 -Wabi" } + +typedef __builtin_va_list __gnuc_va_list; +typedef __gnuc_va_list va_list; + +enum struct A : short { X }; + +void foo(int x, ...) { + va_list vl; + __builtin_va_start(vl, x); + enum A t = __builtin_va_arg(vl, enum A); // { dg-warning "promote" } + __builtin_va_end(vl); +} + +int main() { + foo(0, A::X); // { dg-warning "will not promote" } +} + +// { dg-prune-output "note" }