[v2] c++: Add tree walk case to reach A pack from B in <typename...A,Class<A>...B> [PR118265]

Message ID 173853519910.6.8730848112244089249.586786770@ajryansolutions.co.uk
State New
Headers
Series [v2] c++: Add tree walk case to reach A pack from B in <typename...A,Class<A>...B> [PR118265] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Test passed

Commit Message

A J Ryan Solutions Ltd Feb. 2, 2025, 10:26 p.m. UTC
  This version has all the updates as per feedback from version 1. It makes a minor correction to the code styling, reformats the commit message and moves the test into the cpp1z directory.
In addition I've updated the test to conform with c++17 for better coverage. Andrew Pinski had put one up on the ticket to use, it would be c++20, I can switch it to that if there was another reason to use it that I've overlooked.

Regards
Adam Ryan
  

Comments

Jason Merrill Feb. 3, 2025, 11:52 p.m. UTC | #1
On 2/2/25 5:26 PM, A J Ryan Solutions Ltd wrote:
> This version has all the updates as per feedback from version 1. It 
> makes a minor correction to the code styling, reformats the commit 
> message and moves the test into the cpp1z directory.
> In addition I've updated the test to conform with c++17 for better 
> coverage. Andrew Pinski had put one up on the ticket to use, it would be 
> c++20, I can switch it to that if there was another reason to use it 
> that I've overlooked.

Pushed, thanks!

Jason
  

Patch

From 966d4d2d9cdf7181162f15ff0e167270a8207b32 Mon Sep 17 00:00:00 2001
From: Adam J Ryan <gcc.gnu.org@ajryansolutions.co.uk>
Date: Wed, 1 Jan 2025 13:31:01 +0000
Subject: [PATCH] Add tree walk case to obtain A pack in
 <typename...A,Class<A>...B>.

For non-type parameter packs when unifying the arguments in
unify_pack_expansion it iterates over the associated packs of a param so
that when it recursively unifies the param with the arguments it knows
which targs have been populated with parameter pack arguments that it can
then collect up. This change adds a tree walk so that in the example above
it reaches ...A and adds it to the associated packs for ...B and therefore
knows it will have been set in targs in unify_pack_expansion and processes
it as per other pack arguments.

PR c++/118265

gcc/cp/ChangeLog:

 	* pt.cc (find_parameter_packs_r) <case TEMPLATE_PARM_INDEX>:
 	Walk into the type of a parameter pack.

Signed-off-by: Adam J Ryan <gcc.gnu.org@ajryansolutions.co.uk>
---
 gcc/cp/pt.cc                                   |  5 +++++
 gcc/testsuite/g++.dg/cpp1z/variadic-nontype1.C | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp1z/variadic-nontype1.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 77583dd6bb5..61ba4b98e3d 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -4010,6 +4010,11 @@  find_parameter_packs_r (tree *tp, int *walk_subtrees, void* data)
 		    &find_parameter_packs_r, ppd, ppd->visited);
       return NULL_TREE;
 
+    case TEMPLATE_PARM_INDEX:
+      if (parameter_pack_p)
+        WALK_SUBTREE (TREE_TYPE (t));
+      return NULL_TREE;
+
     case DECL_EXPR:
       {
 	tree decl = DECL_EXPR_DECL (t);
diff --git a/gcc/testsuite/g++.dg/cpp1z/variadic-nontype1.C b/gcc/testsuite/g++.dg/cpp1z/variadic-nontype1.C
new file mode 100644
index 00000000000..ad2af623b13
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/variadic-nontype1.C
@@ -0,0 +1,18 @@ 
+// { dg-do compile { target c++17 } }
+struct Class1
+{
+    void apply_bool(bool){}
+    void apply_char(char){}
+};
+
+template<auto...Fn> struct Class2;
+template<typename...P, void(Class1::*...Fn)(P)> struct Class2<Fn...>
+{
+    void apply(){}
+};
+
+int main()
+{
+    Class2<&Class1::apply_bool, &Class1::apply_char> class2;
+    class2.apply ();
+}
-- 
2.43.0