]> gcc.gnu.org Git - gcc.git/commitdiff
c++: concept-ids and value-dependence [PR102412]
authorPatrick Palka <ppalka@redhat.com>
Wed, 22 Sep 2021 15:16:53 +0000 (11:16 -0400)
committerPatrick Palka <ppalka@redhat.com>
Wed, 6 Oct 2021 13:43:14 +0000 (09:43 -0400)
The problem here is that uses_template_parms returns true for all
concept-ids (even those with non-dependent arguments), so when a concept-id
is used as a default template argument then during deduction the default
argument is considered dependent even after substituting into it, which
leads to deduction failure (from type_unification_real).

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

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.

(cherry picked from commit 9329344a6d81a6a5e3bd171167ebc7b158bb44f4)

gcc/cp/constexpr.c
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp2a/concepts-nondep2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/concepts-nondep3.C [new file with mode: 0644]

index f44def5d955dcb3dc731c0e9f568182c188f7fa9..31facd274e9a02dc45a48f0a7b256170f70382a3 100644 (file)
@@ -7031,7 +7031,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
index 31bd51b7c9df148bcc193b1b00b1c44b67668fda..9e02669962025cf524d3f7654d24030eafeb35fc 100644 (file)
@@ -27061,7 +27061,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:
       {
@@ -27468,18 +27469,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 (file)
index 0000000..e9867f8
--- /dev/null
@@ -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 (file)
index 0000000..4aae287
--- /dev/null
@@ -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
This page took 0.094166 seconds and 5 git commands to generate.