public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Patrick Palka <ppalka@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: jason@redhat.com, Patrick Palka <ppalka@redhat.com>
Subject: [PATCH] c++: direct enum init from type-dep elt [PR112515]
Date: Tue, 14 Nov 2023 11:35:36 -0500	[thread overview]
Message-ID: <20231114163536.1208039-1-ppalka@redhat.com> (raw)

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


             reply	other threads:[~2023-11-14 16:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-14 16:35 Patrick Palka [this message]
2023-11-14 22:32 ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231114163536.1208039-1-ppalka@redhat.com \
    --to=ppalka@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).