public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] c++: dependence of baselink [PR105964]
@ 2022-06-23  3:21 Jason Merrill
  2022-06-23  3:22 ` [pushed] c++: tweak deduction with auto template parms Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Merrill @ 2022-06-23  3:21 UTC (permalink / raw)
  To: gcc-patches

helper<token>::c isn't dependent just because we haven't deduced its return
type yet.  type_dependent_expression_p already knows how to deal with that
for bare FUNCTION_DECL, but needs to learn to look through a BASELINK.

Tested x86_64-pc-linux-gnu, applying to trunk.

	PR c++/105964

gcc/cp/ChangeLog:

	* pt.cc (type_dependent_expression_p): Look through BASELINK.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp1z/nontype-auto21.C: New test.
---
 gcc/cp/pt.cc                                |  9 +++++++++
 gcc/testsuite/g++.dg/cpp1z/nontype-auto21.C | 20 ++++++++++++++++++++
 2 files changed, 29 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp1z/nontype-auto21.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 28edc6ae988..4d1c325432d 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -27960,6 +27960,15 @@ type_dependent_expression_p (tree expression)
       && DECL_INITIAL (expression))
    return true;
 
+  /* Pull a FUNCTION_DECL out of a BASELINK if we can.  */
+  if (BASELINK_P (expression))
+    {
+      if (BASELINK_OPTYPE (expression)
+	  && dependent_type_p (BASELINK_OPTYPE (expression)))
+	return true;
+      expression = BASELINK_FUNCTIONS (expression);
+    }
+
   /* A function or variable template-id is type-dependent if it has any
      dependent template arguments.  */
   if (VAR_OR_FUNCTION_DECL_P (expression)
diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype-auto21.C b/gcc/testsuite/g++.dg/cpp1z/nontype-auto21.C
new file mode 100644
index 00000000000..376d63269cb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/nontype-auto21.C
@@ -0,0 +1,20 @@
+// PR c++/105964
+// { dg-do compile { target c++17 } }
+
+struct token {};
+
+struct example {};
+
+template< typename >
+struct helper
+{
+    static constexpr auto c() { return 42; }
+};
+
+struct impostor_c
+{
+    template< typename T, auto= helper< T >::c >
+    static example func();
+};
+
+example c= impostor_c::func< token >();

base-commit: 349a39f061407ce2339d2ba25da97005f2030c88
-- 
2.27.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [pushed] c++: tweak deduction with auto template parms
  2022-06-23  3:21 [pushed] c++: dependence of baselink [PR105964] Jason Merrill
@ 2022-06-23  3:22 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-06-23  3:22 UTC (permalink / raw)
  To: gcc-patches

While looking at PR105964 I noticed that we were unnecessarily repeating
the deduction loop because of seeing a non-type parameter with type 'auto'.
It is indeed dependent, but not on any other deductions.

Tested x86_64-pc-linux-gnu, applying to trunk.

gcc/cp/ChangeLog:

	* pt.cc (type_unification_real): An auto tparm can't
	be affected by other deductions.
---
 gcc/cp/pt.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 4d1c325432d..80d2bec2348 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -22982,6 +22982,7 @@ type_unification_real (tree tparms,
 	     deduced from a later argument than the one from which
 	     this parameter can be deduced.  */
 	  if (TREE_CODE (tparm) == PARM_DECL
+	      && !is_auto (TREE_TYPE (tparm))
 	      && uses_template_parms (TREE_TYPE (tparm))
 	      && saw_undeduced < 2)
 	    {
@@ -23042,6 +23043,7 @@ type_unification_real (tree tparms,
 
 	  if (saw_undeduced == 1
 	      && TREE_CODE (parm) == PARM_DECL
+	      && !is_auto (TREE_TYPE (parm))
 	      && uses_template_parms (TREE_TYPE (parm)))
 	    {
 	      /* The type of this non-type parameter depends on undeduced

base-commit: 349a39f061407ce2339d2ba25da97005f2030c88
prerequisite-patch-id: d5622f522428b601200c8c234ddb5e58c91dcb06
-- 
2.27.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-23  3:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-23  3:21 [pushed] c++: dependence of baselink [PR105964] Jason Merrill
2022-06-23  3:22 ` [pushed] c++: tweak deduction with auto template parms 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).