Nathaniel Shead f1872cc05b c++: Unwrap type traits defined in terms of builtins within diagnostics [PR117294]
Currently, concept failures of standard type traits just report
'expression X<T> evaluates to false'.  However, many type traits are
actually defined in terms of compiler builtins; we can do better here.
For instance, 'is_constructible_v' could go on to explain why the type
is not constructible, or 'is_invocable_v' could list potential
candidates.

Apart from concept diagnostics, this is also useful when using such
traits in a 'static_assert' directly, so this patch also adjusts the
diagnostics in that context.

As a first step to supporting that we need to be able to map the
standard type traits to the builtins that they use.  Rather than adding
another list that would need to be kept up-to-date whenever a builtin is
added, this patch instead tries to detect any variable template defined
directly in terms of a TRAIT_EXPR.

This patch also adjusts 'diagnose_trait_expr' to provide more helpful
diagnostics for these cases.  Not all type traits have yet been updated,
this patch just updates those that seem particularly valuable or
straight-forward.  The function also gets moved to cp/semantics.cc to be
closer to 'trait_expr_value'.

Various other parts of the compiler are also adjusted here to assist in
making clear diagnostics, such as making more use of 'is_stub_object' to
refer to a type directly rather than in terms of 'std::declval<T>()'.
Additionally, since there are now more cases of nesting within a
'static_assert'ion I felt it was helpful for the experimental-nesting
mode to nest here as well.

	PR c++/117294
	PR c++/113854

gcc/cp/ChangeLog:

	* call.cc (implicit_conversion_error): Hide label when printing
	a stub object.
	(convert_like_internal): Likewise, and nest candidate
	diagnostics.
	* constexpr.cc (diagnose_failing_condition): Nest diagnostics,
	attempt to provide more helpful diagnostics for traits.
	* constraint.cc (satisfy_atom): Pass result before constant
	evaluation to diagnose_atomic_constraint.
	(diagnose_trait_expr): Adjust diagnostics for clarity and
	detail.
	(maybe_diagnose_standard_trait): New function.
	(diagnose_atomic_constraint): Attempt to provide more helpful
	diagnostics for more traits.
	* cp-tree.h (explain_not_noexcept): Declare new function.
	(is_trivially_xible): Add parameter.
	(is_nothrow_xible): Likewise.
	(is_xible): Likewise.
	(is_convertible): Likewise.
	(is_nothrow_convertible): Likewise.
	(diagnose_trait_expr): Declare new function.
	(maybe_diagnose_standard_trait): Declare new function.
	* error.cc (dump_type) <case TREE_VEC>: Handle trait types.
	* except.cc (explain_not_noexcept): New function.
	* method.cc (build_trait_object): Add complain parameter.
	(build_invoke): Propagate complain parameter.
	(assignable_expr): Add explain parameter to show diagnostics.
	(constructible_expr): Likewise.
	(destructible_expr): Likewise.
	(is_xible_helper): Replace trivial flag with explain flag,
	add diagnostics.
	(is_trivially_xible): New explain flag.
	(is_nothrow_xible): Likewise.
	(is_xible): Likewise.
	(is_convertible_helper): Add complain flag.
	(is_convertible): New explain flag.
	(is_nothrow_convertible): Likewise.
	* typeck.cc (cp_build_function_call_vec): Add handling for stub
	objects.
	(convert_arguments): Always return -1 on error.
	* typeck2.cc (cxx_readonly_error): Add handling for stub
	objects.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/any/misc/any_cast_neg.cc: Adjust
	diagnostics.
	* testsuite/20_util/expected/illformed_neg.cc: Likewise.
	* testsuite/20_util/optional/monadic/or_else_neg.cc: Likewise.
	* testsuite/23_containers/array/creation/3_neg.cc: Likewise.
	* testsuite/24_iterators/range_generators/lwg3900.cc: Likewise.
	* testsuite/29_atomics/atomic/requirements/types_neg.cc:
	Likewise.
	* testsuite/30_threads/stop_token/stop_callback/invocable_neg.cc:
	Likewise.
	* testsuite/30_threads/stop_token/stop_callback/destructible_neg.cc:
	Likewise.
	* testsuite/std/format/arguments/args_neg.cc: Likewise.
	* testsuite/std/format/string_neg.cc: Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/concepts-traits3.C: Adjust diagnostics.
	* g++.dg/cpp2a/concepts-traits4.C: New test.
	* g++.dg/diagnostic/static_assert5.C: New test.
	* g++.dg/ext/has_virtual_destructor2.C: New test.
	* g++.dg/ext/is_assignable2.C: New test.
	* g++.dg/ext/is_constructible9.C: New test.
	* g++.dg/ext/is_convertible7.C: New test.
	* g++.dg/ext/is_destructible3.C: New test.
	* g++.dg/ext/is_invocable6.C: New test.
	* g++.dg/ext/is_virtual_base_of_diagnostic2.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2025-07-25 08:18:45 +10:00
2025-06-03 00:18:06 +00:00
2025-05-24 00:17:55 +00:00
2025-07-24 00:20:56 +00:00
2024-07-12 00:17:52 +00:00
2025-06-23 00:16:33 +00:00
2025-07-10 00:20:18 +00:00
2025-01-02 11:59:57 +01:00
2025-05-23 00:17:35 +00:00
2025-04-11 00:17:32 +00:00
2025-01-02 11:59:57 +01:00
2025-06-18 00:18:43 +00:00
2025-01-02 11:59:57 +01:00
2024-10-26 00:19:39 +00:00
2025-07-18 00:19:21 +00:00
2025-07-14 00:16:48 +00:00
2025-06-19 00:20:35 +00:00
2025-07-24 00:20:56 +00:00
2025-07-22 00:19:29 +00:00
2025-04-01 00:19:09 +00:00
2025-07-10 00:20:18 +00:00
2025-05-10 00:17:59 +00:00
2025-01-02 11:59:57 +01:00
2025-07-02 00:19:39 +00:00
2025-04-10 00:18:06 +00:00
2025-01-02 11:59:57 +01:00
2025-05-10 00:17:59 +00:00
2025-03-07 00:17:19 +00:00
2025-07-05 00:19:48 +00:00
2025-07-23 00:20:17 +00:00
2024-11-19 12:27:33 +01: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 1.5 GiB
Languages
C++ 30.7%
C 30%
Ada 14.5%
D 6.1%
Go 5.7%
Other 12.5%