This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++1y] [PATCH 3/4] Ensure implicit template parameters have distinct canonical types.

On 22.09.2013 18:57, Adam Butcher wrote:
The following solves the canonical type issue in the general case
(pointers and refs) and makes it equivalent to the explicit template
case -- in terms of canonical type at least.

for (tree t = TREE_TYPE (TREE_VALUE (p)); t; t = TREE_CHAIN (t))
        TYPE_CANONICAL (t) = t;

The above is insufficient; the traversal doesn't handle function pointers. Currently, to get my local testcases passing, I have the following workaround that abuses find_type_usage. I intend for this to be replaced with a better solution but it will at least mean that people can start experimenting with this feature now (as they appear to be doing This supports that testcase also.


Workaround implicit function template parameter canonical type issue.

* parser.c (add_implicit_template_parms): Workaround to fix up canonical type references left over from before substation of 'auto'. Better
        solution needed but this makes test cases functional.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index f3133f3..4171476 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -28987,6 +28987,25 @@ add_implicit_template_parms (cp_parser *parser, size_t expect_count,
       if (!generic_type_ptr)

+ /* Make the canonical type of each part of the parameter distinct. + FIXME: A better solution is needed for this. Not least the abuse of + find_type_usage. Need foreach_type or similar for proper mutable + access. If something like this does turn out to be necessary then the + find_type_usage loop above can be replaced by a foreach_type that fixes
+        up the canonical types on the way to finding the 'auto'.  */
+      struct helper { static bool fixup_canonical_types (tree t) {
+         t = TREE_TYPE (t);
+         if (!t)
+           return false;
+         if (is_auto_or_concept (t))
+           return true;
+         TYPE_CANONICAL (t) = t;
+         return false;
+      }};
+      find_type_usage (TREE_VALUE (p), (bool (*)(const_tree))
+                      helper::fixup_canonical_types);

       tree synth_id = make_generic_type_name ();

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]