-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std::is_base_of should give correct result for incomplete unions #41188
Comments
assigned to @mclow |
Do you remember the paper/issue that clarified this? |
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 |
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. |
Extended Description
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>);
}
The text was updated successfully, but these errors were encountered: