[gcc/devel/ranger] c++: Fix parameter map handling of member typedef.

Aldy Hernandez aldyh@gcc.gnu.org
Wed Jun 17 18:17:30 GMT 2020


https://gcc.gnu.org/g:55dd44535d2e4e5703c0103c26e7c51ab8c502c4

commit 55dd44535d2e4e5703c0103c26e7c51ab8c502c4
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Jan 23 16:59:54 2020 -0500

    c++: Fix parameter map handling of member typedef.
    
    any_template_parm_r was looking at the args of an alias template-id, but we
    need to look at all args of a member alias/typedef, including implicit ones
    from the enclosing class.
    
            PR c++/93377 - ICE with member alias in constraint.
            * pt.c (any_template_parm_r): Look at template arguments for all
            aliases, not only alias templates.

Diff:
---
 gcc/cp/ChangeLog                             |  6 +++
 gcc/cp/pt.c                                  | 20 ++++-----
 gcc/testsuite/g++.dg/cpp2a/concepts-alias5.C | 62 ++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 11 deletions(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 0ed260b5da1..cddf169ea5b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-01-24  Jason Merrill  <jason@redhat.com>
+
+	PR c++/93377 - ICE with member alias in constraint.
+	* pt.c (any_template_parm_r): Look at template arguments for all
+	aliases, not only alias templates.
+
 2020-01-24  Marek Polacek  <polacek@redhat.com>
 
 	PR c++/93299 - ICE in tsubst_copy with parenthesized expression.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 95719927249..209044135cb 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -10427,19 +10427,15 @@ any_template_parm_r (tree t, void *data)
     }									\
   while (0)
 
+  /* A mention of a member alias/typedef is a use of all of its template
+     arguments, including those from the enclosing class, so we don't use
+     alias_template_specialization_p here.  */
+  if (TYPE_P (t) && typedef_variant_p (t))
+    if (tree tinfo = TYPE_ALIAS_TEMPLATE_INFO (t))
+      WALK_SUBTREE (TI_ARGS (tinfo));
+
   switch (TREE_CODE (t))
     {
-    case RECORD_TYPE:
-    case UNION_TYPE:
-    case ENUMERAL_TYPE:
-      /* Search for template parameters in type aliases.  */
-      if (tree ats = alias_template_specialization_p (t, nt_opaque))
-	{
-	  tree tinfo = TYPE_ALIAS_TEMPLATE_INFO (ats);
-	  WALK_SUBTREE (TI_ARGS (tinfo));
-        }
-      break;
-
     case TEMPLATE_TYPE_PARM:
       /* Type constraints of a placeholder type may contain parameters.  */
       if (is_auto (t))
@@ -10472,6 +10468,8 @@ any_template_parm_r (tree t, void *data)
 	tree cparms = ftpi->ctx_parms;
 	while (TMPL_PARMS_DEPTH (dparms) > ftpi->max_depth)
 	  dparms = TREE_CHAIN (dparms);
+	while (TMPL_PARMS_DEPTH (cparms) > TMPL_PARMS_DEPTH (dparms))
+	  cparms = TREE_CHAIN (cparms);
 	while (dparms
 	       && (TREE_TYPE (TREE_VALUE (dparms))
 		   != TREE_TYPE (TREE_VALUE (cparms))))
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-alias5.C b/gcc/testsuite/g++.dg/cpp2a/concepts-alias5.C
new file mode 100644
index 00000000000..907b0c2e357
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-alias5.C
@@ -0,0 +1,62 @@
+// PR c++/93377
+// { dg-do compile { target c++2a } }
+
+struct empty
+{};
+
+template <typename c>
+c value;
+
+template <typename c>
+auto func(value<c>);
+
+template <typename, typename...>
+struct alignment_algorithm;
+
+template <typename... args_t>
+struct select
+{
+  template <typename algorithm_t, typename... _args_t>
+  decltype(algorithm_t()(func<_args_t>...)) choose();
+
+  template <typename...>
+  static empty choose();
+
+  using type = decltype(choose<alignment_algorithm<int>, args_t...>());
+};
+
+template <typename, typename... args_t>
+struct select_algorithm : select<args_t...>
+{};
+
+template <typename, typename = void> struct maybe_value { int value; };
+
+template <typename cn>
+struct maybe_value<cn, typename cn::sfinae>;
+
+struct function
+{
+  template <typename algorithm_t,
+            typename = decltype(
+                maybe_value<select_algorithm<algorithm_t, int>>::value)>
+  function(algorithm_t);
+};
+
+template <typename>
+struct alignment_configuration_traits
+{
+  static constexpr bool is_vectorised = 0;
+};
+
+template <typename config_t, typename...>
+struct alignment_algorithm
+{
+  using traits_t = alignment_configuration_traits<config_t>;
+  template <typename indexed_sequence_pairs_t>
+  void operator()(indexed_sequence_pairs_t) requires traits_t::is_vectorised;
+};
+
+int main()
+{
+    function{alignment_algorithm<int>{}};
+}


More information about the Gcc-cvs mailing list