<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64373>64373</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Fail to compile a requires-clause for a class method, which checks invocation of another method of the same class.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
andrewerf
</td>
</tr>
</table>
<pre>
Here is the SO post related to this issue: https://stackoverflow.com/questions/76820396/using-a-class-inside-the-requires-clause-for-the-method-of-this-class.
The issue occurs when compiling the following code:
```cpp
#include <type_traits>
#include <ranges>
#include <vector>
struct MyClass
{
void g( int ) {}
void g( char ) {}
template <std::ranges::input_range Rng>
requires requires ( MyClass cls, const std::ranges::range_value_t<Rng>& val )
{
{ cls.g( val ) };
}
void f( Rng&& rng ) {}
};
int main()
{
MyClass cls;
cls.g( 10 );
cls.g( 'a' );
cls.f( std::vector<int>{ 10, 15 } );
}
```
Clang does not compile this program, although other compilers (MSVC and GCC) work as expected. Here is the error produced by Clang:
```
<source>:13:18: error: member access into incomplete type 'MyClass'
13 | { cls.g( val ) };
| ^
<source>:5:8: note: definition of 'MyClass' is not complete until the closing '}'
5 | struct MyClass
| ^
<source>:23:9: error: no matching member function for call to 'f'
23 | cls.f( std::vector<int>{ 10, 15 } );
| ~~~~^
<source>:15:10: note: candidate template ignored: constraints not satisfied [with Rng = std::vector<int>]
15 | void f( Rng&& rng ) {}
| ^
<source>:11:18: note: because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression
11 | requires requires ( MyClass cls, const std::ranges::range_value_t<Rng>& val )
| ^
2 errors generated.
Compiler returned: 1
```
So basically, Clang demands a type in requires-clause to be complete. Moreover, if we change our example slightly, so that `MyClass::f` is never called:
```cpp
#include <type_traits>
#include <ranges>
#include <vector>
struct MyClass
{
void g( int ) {}
void g( char ) {}
template <std::ranges::input_range Rng>
requires requires ( MyClass cls, const std::ranges::range_value_t<Rng>& val )
{
{ cls.g( val ) };
}
void f( Rng&& rng ) {}
};
int main()
{
MyClass cls;
cls.g( 10 );
cls.g( 'a' );
//cls.f( std::vector<int>{ 10, 15 } );
}
```
clang would anyway complain about incompleteness and fail compilation!
```
<source>:13:18: error: member access into incomplete type 'MyClass'
13 | { cls.g( val ) };
| ^
<source>:5:8: note: definition of 'MyClass' is not complete until the closing '}'
5 | struct MyClass
| ^
1 error generated.
Compiler returned: 1
```
The last code snippet is available in Godbolt for the ease of reproduction: https://godbolt.org/z/f7G5PxfKv.
**Expected behavior**: compilation is consistent with other compilers, both programs are accepted.
**Actual behavior**: clang fails to compile both programs.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWEuP2zgS_jX0pWBDotqWffCh2x1ngUWwi81irg2KLEmc0KRCUnY8h_7tg6LkVz8wATKPSxqGWhap4lcfq74qWoSgG4u4ZvMHNn-ciD62zq-FVR4P6OtJ5dRx_S_0CDpAbBE-_wc6FyJ4NCKiguggtjqADqFHVtxDG2MXWHHP-JbxbYhCfnF79LVxh5l0O8a3X3sMUTsbGN-WiyXPitWC8W0ftG2mYiqNCGGqbdAKp7HFqcevvfYYaKQPOK2dT893GFunpq6eEoLhvRnLHll2P1z_3-KAC5yUvQ9waNGCdLtOG22b5E_tjHEH-iadIgdGA4ts-MiuG5_wQltpeoXAik08dvgUvdAxsOLDWzO8sA2-N7hHGZ2_DKZriL6XET4dN-TJOFI-DDcAAHunFTSML0HbCIyvgIbLx7dmyFb4V1PGiRF3He0eIQlRkdPF_Qkv3Wvb9fEpPYH_2eaME8a_045cbmjJEThIExjfgHQ2RHjTfrp_2gvT41NkxWZcgy9gLwyhvl3uQgIrH8j8LLk4zgVyr3h4-cpLVmp6hRbiC1rI2-Y1PVeGhivxvBPaMr48o7rZkmufrzGcQeZZ8uc8dh5gvBSMl7ej45sJ65m5U7BstI1EU_kAeUYM53Py88bCxZdTAA9fN0bYBpTDANbFMQdwSN3Ou8a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