blob: d896acf6034125bb90ed80a26d822ff9f4c81688 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
From 06d3ff4b37b05f4f4f2295222ae3d2818eb8232b Mon Sep 17 00:00:00 2001
From: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 7 Jun 2011 15:12:15 +0000
Subject: [PATCH] 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@174753 138bc75d-0d04-0410-961f-82ee72b054a4
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);
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;
+ }
+};
--
1.7.0.4
|