public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: concept-ids and value-dependence [PR102412]
@ 2021-09-21 13:30 Patrick Palka
  2021-09-22  0:24 ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Palka @ 2021-09-21 13:30 UTC (permalink / raw)
  To: gcc-patches

Here since uses_template_parms returns true for all concept-ids, when a
concept-id is used as a default template argument then during deduction
the default argument is considered dependent even after substitution,
which leads to deduction failure (from type_unification_real).

This patch fixes this by implementing the proposed resolution of CWG 2446
which says a concept-id is dependent only if its arguments are.

Bootstrapped and regtestedon x86_64-pc-linux-gnu, does this look OK for
trunk and perhaps 11?  Also tested on cmcstl2 and range-v3.

	DR 2446
	PR c++/102412

gcc/cp/ChangeLog:

	* constexpr.c (cxx_eval_constant_expression)
	<case TEMPLATE_ID_EXPR>: Check value_dependent_expression_p
	instead of processing_template_decl.
	* pt.c (value_dependent_expression_p) <case TEMPLATE_ID_EXPR>:
	Return true only if any_dependent_template_arguments_p.
	(instantiation_dependent_r) <case CALL_EXPR>: Remove this case.
	<case TEMPLATE_ID_EXPR>: Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/concepts-nondep2.C: New test.
	* g++.dg/cpp2a/concepts-nondep3.C: New test.
---
 gcc/cp/constexpr.c                            |  2 +-
 gcc/cp/pt.c                                   | 15 ++-----------
 gcc/testsuite/g++.dg/cpp2a/concepts-nondep2.C | 21 +++++++++++++++++++
 gcc/testsuite/g++.dg/cpp2a/concepts-nondep3.C |  9 ++++++++
 4 files changed, 33 insertions(+), 14 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-nondep2.C
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-nondep3.C

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 8a5dd067bcb..18d9d117a48 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -7117,7 +7117,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
 	    break;
 	  }
 
-	if (!processing_template_decl
+	if (!value_dependent_expression_p (t)
 	    && !uid_sensitive_constexpr_evaluation_p ())
 	  r = evaluate_concept_check (t);
 	else
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 22c74da7935..17386286269 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -27191,7 +27191,8 @@ value_dependent_expression_p (tree expression)
       }
 
     case TEMPLATE_ID_EXPR:
-      return concept_definition_p (TREE_OPERAND (expression, 0));
+      return concept_definition_p (TREE_OPERAND (expression, 0))
+	&& any_dependent_template_arguments_p (TREE_OPERAND (expression, 1));
 
     case CONSTRUCTOR:
       {
@@ -27598,18 +27599,6 @@ instantiation_dependent_r (tree *tp, int *walk_subtrees,
     case REQUIRES_EXPR:
       return *tp;
 
-    case CALL_EXPR:
-      /* Treat concept checks as dependent. */
-      if (concept_check_p (*tp))
-        return *tp;
-      break;
-
-    case TEMPLATE_ID_EXPR:
-      /* Treat concept checks as dependent.  */
-      if (concept_check_p (*tp))
-	return *tp;
-      break;
-
     case CONSTRUCTOR:
       if (CONSTRUCTOR_IS_DEPENDENT (*tp))
 	return *tp;
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-nondep2.C b/gcc/testsuite/g++.dg/cpp2a/concepts-nondep2.C
new file mode 100644
index 00000000000..e9867f825a1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-nondep2.C
@@ -0,0 +1,21 @@
+// PR c++/102412
+// { dg-do link { target c++20 } }
+
+template<class T, class U> concept C = __is_same(T, U);
+
+template<class T, bool = C<int, T>> void f();
+template<> void f<int, true>() { }
+template<> void f<char, false>() { }
+
+template<bool = C<int, char>> void g();
+template<> void g<false>() { }
+
+template<bool = C<int, int>> void h();
+template<> void h<true>() { }
+
+int main() {
+  f<int>();
+  f<char>();
+  g();
+  h();
+}
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-nondep3.C b/gcc/testsuite/g++.dg/cpp2a/concepts-nondep3.C
new file mode 100644
index 00000000000..ec2d60a43b3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-nondep3.C
@@ -0,0 +1,9 @@
+// DR 2446
+// { dg-do compile { target c++20 } }
+
+template <typename T> concept C = true;
+template <typename T> struct A;
+template <> struct A<bool> { using type = bool; };
+
+template <typename T>
+void f(A<decltype(C<T>)>::type); // OK: no 'typename' needed
-- 
2.33.0.363.g4c719308ce


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

* Re: [PATCH] c++: concept-ids and value-dependence [PR102412]
  2021-09-21 13:30 [PATCH] c++: concept-ids and value-dependence [PR102412] Patrick Palka
@ 2021-09-22  0:24 ` Jason Merrill
  2021-09-22 14:37   ` Patrick Palka
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Merrill @ 2021-09-22  0:24 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 9/21/21 09:30, Patrick Palka wrote:
>       case TEMPLATE_ID_EXPR:
> -      return concept_definition_p (TREE_OPERAND (expression, 0));
> +      return concept_definition_p (TREE_OPERAND (expression, 0))
> +	&& any_dependent_template_arguments_p (TREE_OPERAND (expression, 1));

Hmm, do we even need to check concept_definition_p?  Even if other 
template-ids don't get here, if they did they would also be dependent if 
they had dependent template arguments.

OK either way.

Jason


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

* Re: [PATCH] c++: concept-ids and value-dependence [PR102412]
  2021-09-22  0:24 ` Jason Merrill
@ 2021-09-22 14:37   ` Patrick Palka
  0 siblings, 0 replies; 3+ messages in thread
From: Patrick Palka @ 2021-09-22 14:37 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Patrick Palka, gcc-patches



On Tue, 21 Sep 2021, Jason Merrill wrote:

> On 9/21/21 09:30, Patrick Palka wrote:
> >       case TEMPLATE_ID_EXPR:
> > -      return concept_definition_p (TREE_OPERAND (expression, 0));
> > +      return concept_definition_p (TREE_OPERAND (expression, 0))
> > +	&& any_dependent_template_arguments_p (TREE_OPERAND (expression, 1));
> 
> Hmm, do we even need to check concept_definition_p?  Even if other
> template-ids don't get here, if they did they would also be dependent if they
> had dependent template arguments.

Ah yeah, the concept_definition_p check doesn't seem to be needed.  IIUC
other template-ids can get here but for them we should always return
false at this point since we already checked for type-dependence earlier
in the function (which also checks a_d_t_a_p).

Though to be extra safe I'm inclined to keep the check to avoid
potentially affecting non-concepts code when backporting the patch.

> 
> OK either way.
> 
> Jason
> 
> 


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

end of thread, other threads:[~2021-09-22 14:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-21 13:30 [PATCH] c++: concept-ids and value-dependence [PR102412] Patrick Palka
2021-09-22  0:24 ` Jason Merrill
2021-09-22 14:37   ` Patrick Palka

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).