]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: direct enum init from type-dep elt [PR112515]
authorPatrick Palka <ppalka@redhat.com>
Wed, 15 Nov 2023 17:24:38 +0000 (12:24 -0500)
committerPatrick Palka <ppalka@redhat.com>
Wed, 15 Nov 2023 17:24:38 +0000 (12:24 -0500)
The NON_DEPENDENT_EXPR removal exposed that is_direct_enum_init can be
called in a template context on a CONSTRUCTOR that isn't type-dependent
but whose element is.

PR c++/112515

gcc/cp/ChangeLog:

* decl.cc (is_direct_enum_init): Check type-dependence of the
single element.

gcc/testsuite/ChangeLog:

* g++.dg/template/non-dependent30.C: New test.

gcc/cp/decl.cc
gcc/testsuite/g++.dg/template/non-dependent30.C [new file with mode: 0644]

index d2ed46b145318b1d677550d3fa418b1ed884b6be..b8e1098d482250b4e11c863d0cb39b5807e37e44 100644 (file)
@@ -6614,6 +6614,7 @@ is_direct_enum_init (tree type, tree init)
       && CONSTRUCTOR_NELTS (init) == 1
       /* DR 2374: The single element needs to be implicitly
         convertible to the underlying type of the enum.  */
+      && !type_dependent_expression_p (CONSTRUCTOR_ELT (init, 0)->value)
       && can_convert_arg (ENUM_UNDERLYING_TYPE (type),
                          TREE_TYPE (CONSTRUCTOR_ELT (init, 0)->value),
                          CONSTRUCTOR_ELT (init, 0)->value,
diff --git a/gcc/testsuite/g++.dg/template/non-dependent30.C b/gcc/testsuite/g++.dg/template/non-dependent30.C
new file mode 100644 (file)
index 0000000..32d48e4
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/112515
+// { dg-do compile { target c++11 } }
+
+enum E : int { };
+
+template<class T>
+E f(T t) {
+  return E{t.e};
+}