<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/121278>121278</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Incorrect handling of incomplete types in `std::derived_from`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
cor3ntin
</td>
</tr>
</table>
<pre>
Per https://eel.is/c++draft/meta#lib:is_base_of,
> Derived shall be a complete type
This is generally enforced by `__is_base_of` (the builtin used to implement `is_base_of_v`)
However, in libc++, `derived_from` is defined as
https://github.com/llvm/llvm-project/blob/cb1ad985b53c87b53974e37bba60129acb294f0d/libcxx/include/__concepts/derived_from.h#L27
And because the constraints are only enforced in `__is_base_of` which is not in the immediate context of the `is_base_of_v` constraint, substituting an incomplete class in `is_base_of_v` does not result in a substitution failure in the immediate context (which should just cause `derived_from` to not be satisfied per https://eel.is/c++draft/temp.constr.atomic#3.sentence-2) but instead makes the program ill-formed, which i believe is non-conforming.
Note that GCC diverges in all cases. MSVC and EDG exposes what I believe to be the correct behavior.
I think there are 2 solutions:
- Modify `derived_from` to use `__is_base_of` directly (which is what libstdc++ and MS STL do)
- Add a require clause to `std::is_base_of_v` to check for completeness
https://godbolt.org/z/zGrKEKEao
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVF1v4zYQ_DX0y8KCTPpDetCDL4nT4C5FgRz6avBjZe2FIl2ScuL--oKSL3HvckAL2BAgkTuzM7sjY6SDQ2zY6hNb3c7kkDofGu2DcIncTHlzbv7AAF1Kx8jElvEd4ztEW1BkfKcZ_8T4JxNkmxjf9Zgk48KSYmJLca9kxL1vGb8BYOU2_8Qd3GKgExqInbQWFIIE7fujxYSQzkecTn7tKAJFOKDDIK09A7rWB40G1BnYutzvrxDWJTBepQ5BDWQTORgiGkgeKFfu0aV85_3G_sTWJeP1BPabf8EThkyUHFhSl8byC7Yuz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