8sa1-gcc/gcc/cp/type-utils.h
Patrick Palka 6bd409cfc8 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.
2021-02-25 19:55:43 -05:00

55 lines
1.8 KiB
C

/* Utilities for querying and manipulating type trees.
Copyright (C) 2013-2021 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#ifndef GCC_CP_TYPE_UTILS_H
#define GCC_CP_TYPE_UTILS_H
/* Returns the first tree within T that is directly matched by PRED. T may be a
type or PARM_DECL and is incrementally decomposed toward its type-specifier
until a match is found. NULL is returned if PRED does not match any
part of T.
This is primarily intended for detecting whether T uses `auto' or a concept
identifier. Since either of these can only appear as a type-specifier for
the declaration in question, only top-level qualifications are traversed;
find_type_usage does not look through the whole type. */
inline tree
find_type_usage (tree t, bool (*pred) (const_tree))
{
if (pred (t))
return t;
enum tree_code code = TREE_CODE (t);
if (code == POINTER_TYPE || code == REFERENCE_TYPE
|| code == PARM_DECL || code == OFFSET_TYPE
|| code == FUNCTION_TYPE || code == METHOD_TYPE
|| code == ARRAY_TYPE)
return find_type_usage (TREE_TYPE (t), pred);
if (TYPE_PTRMEMFUNC_P (t))
return find_type_usage
(TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (t)), pred);
return NULL_TREE;
}
#endif // GCC_CP_TYPE_UTILS_H