public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/48780 (non-promotion of scoped enums)
@ 2011-05-21 12:22 Jason Merrill
  2011-05-22 13:24 ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Merrill @ 2011-05-21 12:22 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 284 bytes --]

As the bug submitter correctly points out, C++0x scoped enums are not 
subject to integral promotion like unscoped enums are.  Unfortunately, 
this represents an ABI change (at least for varargs), so it's 
conditional on -fabi-version.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: 48780.patch --]
[-- Type: text/x-patch, Size: 1761 bytes --]

commit e2aa4734d644e2c0d658d6d9a42cc36ef2b0087c
Author: Jason Merrill <jason@redhat.com>
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..e89ce29 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
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);
+}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-06-07 15:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-21 12:22 C++ PATCH for c++/48780 (non-promotion of scoped enums) Jason Merrill
2011-05-22 13:24 ` Jason Merrill
2011-06-07 15:12   ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).