* [PATCH] c++: direct enum init from type-dep elt [PR112515]
@ 2023-11-14 16:35 Patrick Palka
2023-11-14 22:32 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2023-11-14 16:35 UTC (permalink / raw)
To: gcc-patches; +Cc: jason, Patrick Palka
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
OK for trunk?
-- >8 --
The NON_DEPENDENT_EXPR removal exposed that is_direct_enum_init may end
up checking convertibility of a type-dependent argument.
PR c++/112515
gcc/cp/ChangeLog:
* decl.cc (is_direct_enum_init): Return false if the single
element is type-dependent.
gcc/testsuite/ChangeLog:
* g++.dg/template/non-dependent30.C: New test.
---
gcc/cp/decl.cc | 1 +
gcc/testsuite/g++.dg/template/non-dependent30.C | 9 +++++++++
2 files changed, 10 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/template/non-dependent30.C
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 4a07c7e879b..4be4847810a 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -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
index 00000000000..32d48e44c09
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/non-dependent30.C
@@ -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};
+}
--
2.43.0.rc1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: direct enum init from type-dep elt [PR112515]
2023-11-14 16:35 [PATCH] c++: direct enum init from type-dep elt [PR112515] Patrick Palka
@ 2023-11-14 22:32 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2023-11-14 22:32 UTC (permalink / raw)
To: Patrick Palka, gcc-patches
On 11/14/23 11:35, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
> OK for trunk?
OK.
> -- >8 --
>
> The NON_DEPENDENT_EXPR removal exposed that is_direct_enum_init may end
> up checking convertibility of a type-dependent argument.
>
> PR c++/112515
>
> gcc/cp/ChangeLog:
>
> * decl.cc (is_direct_enum_init): Return false if the single
> element is type-dependent.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/template/non-dependent30.C: New test.
> ---
> gcc/cp/decl.cc | 1 +
> gcc/testsuite/g++.dg/template/non-dependent30.C | 9 +++++++++
> 2 files changed, 10 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/template/non-dependent30.C
>
> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
> index 4a07c7e879b..4be4847810a 100644
> --- a/gcc/cp/decl.cc
> +++ b/gcc/cp/decl.cc
> @@ -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
> index 00000000000..32d48e44c09
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/non-dependent30.C
> @@ -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};
> +}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-14 22:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-14 16:35 [PATCH] c++: direct enum init from type-dep elt [PR112515] Patrick Palka
2023-11-14 22:32 ` 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).