LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 41843 - std::is_base_of should give correct result for incomplete unions
Summary: std::is_base_of should give correct result for incomplete unions
Status: RESOLVED FIXED
Alias: None
Product: libc++
Classification: Unclassified
Component: All Bugs (show other bugs)
Version: 8.0
Hardware: Macintosh All
: P normal
Assignee: Marshall Clow (home)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-11 09:03 PDT by Alisdair Meredith
Modified: 2019-06-17 08:45 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments
Source for failing test (326 bytes, text/x-csrc)
2019-05-11 09:03 PDT, Alisdair Meredith
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alisdair Meredith 2019-05-11 09:03:19 PDT
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>);
}
Comment 1 Marshall Clow (home) 2019-05-11 09:28:51 PDT
Do you remember the paper/issue that clarified this?
I can find it, but you probably have it on the tip of your fingers.
Comment 2 Alisdair Meredith 2019-05-11 10:21:39 PDT
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.
Comment 3 Marshall Clow (home) 2019-05-11 11:23:30 PDT
Whenever possible, libc++ calls the compiler intrinsic `__is_base_of` to have the compiler do the work.
Comment 4 Marshall Clow (home) 2019-05-11 11:26:41 PDT
Running the test w/o using the compiler intrinsic produces the expected results.
Comment 5 Marshall Clow (home) 2019-05-13 06:54:23 PDT
Both gcc and MSVC compile the code that Alisdair posted w/o error.
Comment 6 Marshall Clow (home) 2019-05-13 10:14:43 PDT
Patch up for review: https://reviews.llvm.org/D61858
Comment 7 Marshall Clow (home) 2019-06-17 08:45:16 PDT
resolved by revision 360614.