<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/96660>96660</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`requires` expression failure could provide more helpful diagnostics
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mpusz
</td>
</tr>
</table>
<pre>
I initially had such an implementation of the concept:
```cpp
template<typename Q1, typename Q2>
concept A =
Quantity<Q1> && Quantity<Q2> &&
requires { common_reference(Q1::reference, Q2::reference); };
};
```
The above produces the following error message on failure:
```
note: because 'A<quantity<hertz{{{{{}}}}}, int>, quantity<struct becquerel{{{{{}}}}}, int> >' evaluated to false
511 | requires A<quantity<R1, Rep1>, quantity<R2, Rep2>>
| ^
note: because 'common_reference(Q1::reference, Q2::reference)' would be invalid: no matching function for call to 'common_reference'
113 | requires { common_reference(Q1::reference, Q2::reference); } &&
| ^
```
This log is not useful because the user does not know what `Q1::reference` and `Q2::reference` are.
So, I added the following:
```cpp
template<auto R1, auto R2>
concept HaveCommonReference = requires { common_reference(R1, R2); };
template<typename Q1, typename Q2>
concept A =
Quantity<Q1> && Quantity<Q2> &&
HaveCommonReference<Q1::reference, Q2::reference>
};
```
but it still provides the following:
```
note: because 'A<quantity<hertz{{{{{}}}}}, int>, quantity<struct becquerel{{{{{}}}}}, int> >' evaluated to false
512 | requires A<quantity<R1, Rep1>, quantity<R2, Rep2>>
| ^
note: because 'HaveCommonReference<quantity<hertz{{{{{}}}}}, int>::reference, quantity<struct becquerel{{{{{}}}}}, int>::reference>' evaluated to false
115 | HaveCommonReference<Q1::reference, Q2::reference> &&
| ^
../../src/core/include/mp-units/framework/quantity.h:106:42: note: because 'common_reference(R1, R2)' would be invalid: no matching function for call to 'common_reference'
106 | concept HaveCommonReference = requires { common_reference(R1, R2); };
| ^
```
It would be great to get better information at this level by saying what `R1` and `R2` are.
As a workaround, I had to go even deeper with such a change:
```cpp
template<auto R1, auto R2>
concept HaveCommonReferenceImpl = requires { common_reference(R1, R2); };
template<auto R1, auto R2>
concept HaveCommonReference = HaveCommonReferenceImpl<R1, R2>;
```
and finally, I have this error message
```
note: because 'A<quantity<hertz{{{{{}}}}}, int>, quantity<struct becquerel{{{{{}}}}}, int> >' evaluated to false
511 | requires A<quantity<R1, Rep1>, quantity<R2, Rep2>>
| ^
note: because 'HaveCommonReference<quantity<hertz{{{{{}}}}}, int>::reference, quantity<struct becquerel{{{{{}}}}}, int>::reference>' evaluated to false
114 | HaveCommonReference<Q1::reference, Q2::reference> &&
| ^
note: because 'HaveCommonReferenceImpl<mp_units::si::hertz{{{{{}}}}}, struct becquerel{{{{{}}}}}>' evaluated to false
106 | concept HaveCommonReference = HaveCommonReferenceImpl<R1, R2>;
| ^
note: because 'common_reference(R1, R2)' would be invalid: no matching function for call to 'common_reference'
103 | concept HaveCommonReferenceImpl = requires { common_reference(R1, R2); };
| ^
```
However, we probably agree this is not what we want the users to write to get meaningful diagnostics?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWEuTmzgQ_jXypSsuEAbbBw4eT1yZY2b3nhLQgDZCInqYdX79lniMPZ6Xs_FsqlJLUTZI0Or-uvV9EswYXknElMQ3JL6dMWdrpdOmdeb7LFPFIb0DLrnlTIgD1KwA4_IamATetAIblJZZriSoEmyNkCuZY2tJtCHBLQmm3yQYzrxthxaLTSuYRRJt7aFFyRqEzyGhWzjeUhJ9HJ4ercIGSHQ7NAF8dkxabg8k2n4OSfQRCE0ITR6102P79JrGb45rNECWN5CrplHyi8YSNcocCV15WxsSbU7atr0vZ41rEt0AWd6S6GYM8vR6CvgUhT9rBJapPUKrVeFyND1kpRJCdVxWgForDQ0awyoEJaFkXDiNL6E53ErlYdxAhjlzBoHQ5YZE229HGGrU9jtZ3jw-bx-ddAtcWo843cLJu8Zql1tv_JtDjeJSM9CbWgLumXDMYgFWQcmEwSkREIchkOUW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