Created attachment 21928 [details] Source for failing test C++20 clarifies the expectation for detecting traits that cannot determine a result due to an incomplete class. However, is_base_of is expected to recognize that unions can never have a base class, nor ever be a base class, and so give the correct result - per the current working draft. The following code is expected to compile without triggering a static assert. For the current clang/libc++, it fails to compile the middle two heterogeneous assertions: #include <type_traits> struct Incomplete; union Uncomplete; int main() { static_assert( std::is_base_of_v<Incomplete, Incomplete>); static_assert(!std::is_base_of_v<Incomplete, Uncomplete>); // fails to compile static_assert(!std::is_base_of_v<Uncomplete, Incomplete>); // fails to compile static_assert(!std::is_base_of_v<Uncomplete, Uncomplete>); }
Do you remember the paper/issue that clarified this? I can find it, but you probably have it on the tip of your fingers.
I think we were both thinking of http://wg21.link/p1285 but it turns out not to be relevant, as that was about pointers and references to incomplete types. I believe the standard wording has required properly supporting incomplete union types in this specific trait for some time.
Whenever possible, libc++ calls the compiler intrinsic `__is_base_of` to have the compiler do the work.
Running the test w/o using the compiler intrinsic produces the expected results.
Both gcc and MSVC compile the code that Alisdair posted w/o error.
Patch up for review: https://reviews.llvm.org/D61858
resolved by revision 360614.