<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/107578>107578</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Order of template specialization matters when it should not
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kim366
</td>
</tr>
</table>
<pre>
When uncommenting the commented line, the code fails to compile on clang (trunk and various other versions). In gcc, this code compiles fine. When moving the template specialization above the definition of `S`, the code compiles fine. It seems, that the introduction of `is_defined` causes the concept to be evaluated too early.
```cpp
#include <concepts>
#include <iostream>
template<int>
struct special;
template<int i>
concept is_special_defined = std::same_as<decltype(special<i>::value), const int>;
template<int i>
struct with_special
{
/// if we uncomment this line, when the template specialization is placed below the first use of with_special<2>, the constraint check will fail
/// note: we are not even using is_defined, only defining it
constexpr static auto is_defined = is_special_defined<i>;
auto get_special() requires is_special_defined<i> { return special<i>::value; };
};
struct S {
with_special<2> x;
};
template<>
struct special<2>
{
constexpr static auto value = 7;
};
int main() {
auto s = S{};
std::cout << s.x.get_special();
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVcFu4zgM_RrlQkzgyokdH3xo0y0wpz30sMdClplYW1nyilTS7tcvpDhJM20HCxgKLJKPj-RjrIjM3iG2Yv0g1o8LFXnwoX01Y1lVi8737-1fAzqITvtxRMfG7YEHhPkVe7DGoZDb-bZH2CljCdgnn8lYBO9AW-X2IOSGQ3SvoFwPBxWMjwSeBwxwwEDGOxKyWcJPB3utT6CGTqgzGMHOOFxCZjX6w5kP4zhZxQg0oTbKmn8VG-9Adf6A2aPHnXEmX_odiKp4FlVxQ_yXFD8ZCHGkk4_i7GgcB99H_QHH0EvGxl5UBWgVCWkGdRonTq3oEPCgbFSpY-w9oAr2fSmKR1Hcz2dVnB49TfONLI3TNvYIotzOaCTKP74yG08cUI1Xcz7PfUkeji9G4hA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