Skip to content
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

Closed
AlisdairM mannequin opened this issue May 11, 2019 · 8 comments
Closed

std::is_base_of should give correct result for incomplete unions #41188

AlisdairM mannequin opened this issue May 11, 2019 · 8 comments
Assignees
Labels
bugzilla libc++

Comments

@AlisdairM
Copy link
Mannequin

@AlisdairM AlisdairM mannequin commented May 11, 2019

Bugzilla Link 41843
Resolution FIXED
Resolved on Jun 17, 2019 08:45
Version 8.0
OS All
Attachments Source for failing test
CC @mclow,@zygoloid

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>);
}

@AlisdairM
Copy link
Mannequin Author

@AlisdairM AlisdairM mannequin commented May 11, 2019

assigned to @mclow

@mclow
Copy link
Contributor

@mclow mclow commented May 11, 2019

Do you remember the paper/issue that clarified this?
I can find it, but you probably have it on the tip of your fingers.

@AlisdairM
Copy link
Mannequin Author

@AlisdairM AlisdairM mannequin commented May 11, 2019

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.

@mclow
Copy link
Contributor

@mclow mclow commented May 11, 2019

Whenever possible, libc++ calls the compiler intrinsic __is_base_of to have the compiler do the work.

@mclow
Copy link
Contributor

@mclow mclow commented May 11, 2019

Running the test w/o using the compiler intrinsic produces the expected results.

@mclow
Copy link
Contributor

@mclow mclow commented May 13, 2019

Both gcc and MSVC compile the code that Alisdair posted w/o error.

@mclow
Copy link
Contributor

@mclow mclow commented May 13, 2019

Patch up for review: https://reviews.llvm.org/D61858

@mclow
Copy link
Contributor

@mclow mclow commented Jun 17, 2019

resolved by revision 360614.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla libc++
Projects
None yet
Development

No branches or pull requests

1 participant