aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2021-04-23 08:28:58 -0400
committerPatrick Palka <ppalka@redhat.com>2021-04-23 08:28:58 -0400
commit5f8aed72e76970d2c6fa06fb23fdaa47660555b0 (patch)
tree17888290d6de3fa35ec098cd55538bf4b16366ba /gcc
parent35b2be219fc1934ae040d045e355680a83d839c4 (diff)
downloadgcc-5f8aed72e76970d2c6fa06fb23fdaa47660555b0.zip
gcc-5f8aed72e76970d2c6fa06fb23fdaa47660555b0.tar.gz
gcc-5f8aed72e76970d2c6fa06fb23fdaa47660555b0.tar.bz2
c++: Refine enum direct-list-initialization [CWG2374]
This implements the wording changes of CWG2374, which clarifies the wording of P0138 to forbid e.g. direct-list-initialization of a scoped enumeration from a different scoped enumeration. gcc/cp/ChangeLog: DR 2374 * decl.c (is_direct_enum_init): Check the implicit convertibility requirement added by CWG 2374. gcc/testsuite/ChangeLog: DR 2374 * g++.dg/cpp1z/direct-enum-init2.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/decl.c8
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/direct-enum-init2.C8
2 files changed, 15 insertions, 1 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index b81de8e..60dc2bf 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6191,7 +6191,13 @@ is_direct_enum_init (tree type, tree init)
&& ENUM_FIXED_UNDERLYING_TYPE_P (type)
&& TREE_CODE (init) == CONSTRUCTOR
&& CONSTRUCTOR_IS_DIRECT_INIT (init)
- && CONSTRUCTOR_NELTS (init) == 1)
+ && CONSTRUCTOR_NELTS (init) == 1
+ /* DR 2374: The single element needs to be implicitly
+ convertible to the underlying type of the enum. */
+ && can_convert_arg (ENUM_UNDERLYING_TYPE (type),
+ TREE_TYPE (CONSTRUCTOR_ELT (init, 0)->value),
+ CONSTRUCTOR_ELT (init, 0)->value,
+ LOOKUP_IMPLICIT, tf_none))
return true;
return false;
}
diff --git a/gcc/testsuite/g++.dg/cpp1z/direct-enum-init2.C b/gcc/testsuite/g++.dg/cpp1z/direct-enum-init2.C
new file mode 100644
index 0000000..5b94a8d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/direct-enum-init2.C
@@ -0,0 +1,8 @@
+// DR 2374
+// { dg-do compile { target c++17 } }
+
+enum class Orange;
+enum class Apple;
+
+extern Orange o;
+Apple a{o}; // { dg-error "cannot convert" }