Patrick Palka 12f461009b c++: constrained auto NTTP vs associated constraints
According to [temp.param], the constraint on an auto NTTP is an
associated constraint and so should be checked as part of satisfaction
of the overall associated constraints, but we currently don't include
them in the template's associated constraints and instead check them
separately during template argument coercion/deduction.

Fixing this is mostly a matter of storing the NTTP's constraint inside
TEMPLATE_PARM_CONSTRAINTS instead of PLACEHOLDER_TYPE_CONSTRAINTS and
generalizing the relevant template parameter processing subroutines to
also handle such NTTPs.

While this is straightfoward for "simple" constrained autos, it was
later noticed that for e.g. 'C auto* P' or 'D auto& Q' it's not clear
how to express their constraint as an associated constraint.  For P an
option would be C<decltype(*P)>, but for Q it's not clear how to pass
the referenced type to C.  C<decltype(auto(Q))> would be wrong because
we don't want to decay function/array types.

So this patch sidesteps this question by preserving the existing
behavior for such "non-simple" constrained auto (i.e. don't add them
to the associated constraints, and continue ad-hoc checking them during
do_auto_deduction).  The simple case is by far the most common anyway.

The main observeable difference with this change is that such
constrained auto NTTPs are now involved in the "more constrained"
determination during partial ordering.

gcc/cp/ChangeLog:

	* constraint.cc (finish_shorthand_constraint): Add is_non_type
	parameter.  Handle constrained auto NTTPs.
	* cp-tree.h (copy_template_args): Declare.
	(expand_template_argument_pack): Declare.
	(finish_shorthand_constraint): Adjust declaration.
	* mangle.cc (write_template_param_decl): Obtain constraints of
	an auto NTTP through TEMPLATE_PARM_CONSTRAINTS instead of
	PLACEHOLDER_TYPE_CONSTRAINTS.
	* parser.cc (cp_parser_constrained_type_template_parm): Inline
	into its only caller and remove.
	(cp_parser_constrained_non_type_template_parm): Likewise.
	(finish_constrained_parameter): Simplify after the above.  Replace
	the type of an ordinary constrained auto NTTP with a
	non-constrained one and set TEMPLATE_PARM_CONSTRAINTS for it.
	(cp_parser_template_parameter): Dispatch to
	finish_constrained_parameter for a constrained auto NTTP.
	* pt.cc (process_template_parm): Pass is_non_type to
	finish_shorthand_constraint.  Use TEMPLATE_PARM_CONSTRAINTS
	instead of TREE_TYPE for clarity.
	(expand_template_argument_pack): Remove forward declaration.
	(copy_template_args): Likewise.
	(make_constrained_placeholder_type): Return the type not the
	TYPE_NAME for consistency with make_auto_1 etc.
	(do_auto_deduction): Assert we no longer see simple constrained
	autos during coercion/deduction.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp26/pack-indexing15.C: Adjust expected error upon
	constrained auto NTTP satisfaction failure.
	* g++.dg/cpp2a/concepts-placeholder12.C: Likewise.
	* g++.dg/cpp2a/concepts-pr97093.C: Likewise.
	* g++.dg/cpp2a/concepts-template-parm2.C: Likewise.
	* g++.dg/cpp2a/concepts-template-parm6.C: Likewise.
	* g++.dg/cpp2a/concepts-template-parm12.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2026-02-12 18:20:36 -05:00
2026-02-05 00:16:28 +00:00
2026-02-06 00:16:39 +00:00
2026-02-06 00:16:39 +00:00
2026-01-31 00:16:35 +00:00
2026-01-31 00:16:35 +00:00
2026-01-30 00:16:31 +00:00
2026-01-31 00:16:35 +00:00
2026-02-07 00:16:36 +00:00
2026-02-06 00:16:39 +00:00
2026-01-27 00:16:29 +00:00
2026-02-06 00:16:39 +00:00

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.
Description
No description provided
Readme 4.2 GiB
Languages
C++ 30.7%
C 30.2%
Ada 14.4%
D 6.1%
Go 5.7%
Other 12.4%