GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
c++

Improve `diagnostics-all-candidates` with C++ concepts.

Ensures `-fdiagnostics-all-candidates` shows all failing candidates, not just the first.

This commit fixes an issue with the -fdiagnostics-all-candidates flag in the C++ compiler when C++ concepts are involved. Previously, if a template instantiation had one candidate with a conversion error and others with unsatisfied constraints, the diagnostic would only report the conversion error. The flag did not help in revealing the unsatisfied constraints of other candidates. The fix ensures that all failing candidates, including those with unsatisfied constraints, are reported when this flag is used, providing more comprehensive error information.

In Details

In gcc/cp/call.cc, the function splice_viable is modified to be stricter when -fdiagnostics-all-candidates is enabled. This change ensures that when multiple viable candidates exist for a function call, and one has a conversion error while others have unsatisfied constraints, all such failing candidates are considered and reported. This addresses a limitation where only the primary error (e.g., bad conversion) was shown, obscuring other reasons for template non-deduction or overload resolution failures.

For Context
diagnostics
Messages issued by the compiler to report errors, warnings, or informational notes about the source code. These help developers identify and fix problems.
-fdiagnostics-all-candidates
A GCC compiler flag that instructs the compiler to report all viable candidates during overload resolution or template instantiation, even if one candidate appears to be a better match or has a simpler error. This aids in debugging complex template metaprogramming or overload resolution issues.
C++ concepts
A C++20 feature that allows programmers to specify constraints on template parameters. Concepts enable compile-time checking of template arguments, improving error messages and code clarity.
overload resolution
The process by which the C++ compiler determines which function or operator overload to call when there are multiple functions with the same name but different parameter lists.
template instantiation
The process where the compiler generates a specific version of a class or function template for a given set of template arguments.
Filed Under: c++diagnosticsconceptstemplates