c++: abbreviated function template return type rewriting [PR98990]
authorPatrick Palka <ppalka@redhat.com>
Fri, 26 Feb 2021 00:55:43 +0000 (19:55 -0500)
committerPatrick Palka <ppalka@redhat.com>
Fri, 26 Feb 2021 00:55:43 +0000 (19:55 -0500)
commit6bd409cfc83683a9be5c6b3b8f9a3ec8959f9356
tree0de9b13388914af63a614a70b41415f197cf0df3
parentdaa6884432b09b0ec1207dacf1a467dd90538360
c++: abbreviated function template return type rewriting [PR98990]

When an abbreviated function template has a complex placeholder return
type such auto& or auto**, the level adjustment performed by
splice_late_return_type directly replaces the 'auto' inside the original
return type with the level-adjusted 'auto', but that breaks
TYPE_CANONICAL caching.  Instead, we should rebuild the entire return
type using the adjusted 'auto'.

This patch makes this happen by tsubsting the original return type with
an argument vector that maps the original 'auto' to the adjusted 'auto'.
In passing, this patch also reverts the misguided changes to
find_type_usage in r10-6571 that made find_type_usage return a tree*
instead of a tree so as to discourage this kind of in-place type
modification.

It occurred to me that the constraint also needs to be rebuilt so that
it refers to the adjusted 'auto', but this oversight doesn't seem to
cause any issues at the moment due to how do_auto_deduction "manually"
substitutes the 'auto' inside the constraint before performing
satisfaction.  So this'll be fixed later as part of a rework of
placeholder type constraint checking.

gcc/cp/ChangeLog:

PR c++/98990
* pt.c (splice_late_return_type): Rebuild the entire return type
if we have to adjust the level of an auto within.
(type_uses_auto): Adjust call to find_type_usage.
* type-utils.h (find_type_usage): Revert r10-6571 change that
made this function return a pointer to the auto node.

gcc/testsuite/ChangeLog:

PR c++/98990
* g++.dg/concepts/abbrev8.C: New test.
gcc/cp/pt.c
gcc/cp/type-utils.h
gcc/testsuite/g++.dg/concepts/abbrev8.C [new file with mode: 0644]