<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/102059>102059</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[concepts] Increase diagnostics verbosity for substitution failures
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ldalessa
</td>
</tr>
</table>
<pre>
I have a sequence of template functions that forward to each other and all depend on the same concept, like if a trait has been specialized for the type. When I call the outer function the diagnostic doesn't include a useful reason for the diagnostic failure. This makes debugging things like missing traits intractable for third-party users.
Gcc will at least drill down into the full stack of failures to indicate what's going on. I don't really like the verbosity of its output either, but at least it says something useful.
As an example https://godbolt.org/z/a3PMGKc44:
```c++
#include <concepts>
#include <type_traits>
template <class>
struct trait {};
template <class T>
concept has_trait = requires {
trait<T>::value;
};
template <has_trait T>
inline constexpr auto trait_v = trait<T>::value;
template <has_trait T>
auto foo(T) -> decltype(trait_v<T>) {
return trait_v<T>;
}
template <has_trait T>
auto bar(T t) -> decltype(foo(t)) {
foo(t);
}
int main()
{
bar(0);
}
```
Clang gives me the following output, which really doesn't give me any information about why `bar` is failing.
```c++
<source>:27:5: error: no matching function for call to 'bar'
27 | bar(0);
| ^~~
<source>:21:6: note: candidate template ignored: substitution failure [with T = int]: no matching function for call to 'foo'
21 | auto bar(T t) -> decltype(foo(t)) {
| ^ ~~~
```
Gcc on the other hand vomits this up, which tells me that the trait isn't correctly specialized.
```c++
<source>:21:6: note: candidate: 'template<class T> requires has_trait<T> decltype (foo(t)) bar(T)'
21 | auto bar(T t) -> decltype(foo(t)) {
| ^~~
<source>:21:6: note: template argument deduction/substitution failed:
<source>:21:6: note: constraints not satisfied
<source>: In substitution of 'template<class T> requires has_trait<T> decltype (foo(t)) bar(T) [with T = int]':
<source>:27:8: required from here
27 | bar(0);
| ~~~^~~
<source>:8:9: required for the satisfaction of 'has_trait<T>' [with T = int]
<source>:8:21: in requirements [with T = int]
<source>:9:15: note: the required expression 'trait<T>::value' is invalid
9 | trait<T>::value;
| ^~~~~
```
If I stop containing this call stack clang gives me a wonderful error https://godbolt.org/z/WxoYrMPod.
```c++
<source>:8:43: error: no member named 'value' in 'trait<int>'
8 | inline constexpr auto trait_v = trait<T>::value;
| ~~~~~~~~~~^
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0V01v27oS_TX0ZhBDpqzIXnjhfPgieLjAXQQo3qqgyJHFV4p0Scquu8hvfxhKsZzUSdNe1DD8IZEzZ86cmaFECHprEVesuGHF3UR0sXF-ZZQwGIKYVE4dVw_QiD2CgIBfO7QSwdUQsd0ZERHqzsqonQ0QGxGhdv4gvILoAIVswMUGPQirQBgDCndoFTgLsUEIokWQzkrcRcZvwegvCLoGAdELHaERASpEC2GHUgujv6MiB2lzPO5wCp8atPAAkozTVddF9CdM6ZLSYmtdiFqCchgs42UEbaXpFAXVBaw7Ax5FcPZk_WxTLbTpPE7hsdEBWvEFAyisuu1W2y3ERttt6KG3OoR0jdAH0DZ6IaOoDA52tVdXO-Hjkbz6MAWW3bFs3X_-JSUctDEgIhgUIYLy9Fe5gyVbLgGrO2MgRCG_UBYGbIHo1lZpSRk5NCIyXgbYOkLj7BQeQLk-cI_CmGOPl-zt0Vcu6Hgkc4TadXHXRUBNiaOsVF0cIekIQRwDBNdiCn3gb3oeyTqAsIDfRLszCE2Mu8DyNeMbxjdbpypn4tT5LeOb74xvRP7P33_9R87ntObMCrvO-rdk_Ibe_VWeP-eO5beDeALL7y_dJo187rMxrkifJ_mSESPCeD9E38k4KJCVN6y8Y_nNu3vh8bR7AETS_TyYyO_A49dOU5rIXlrX22f5bdqar1m-3gvT4ejqXbej-dG1tkbbVE8h4redB9GRZmjV532C8VOfH_KTzNbOMb54ZHwJVyy_B4XSENuMLwaPz3748ixqAPAYO2_h1arzsH8VSyU8YYF4CU0PlG69RHJ2_Q3f2kZohbaML2jVsOQskt5vd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