[libcxx-commits] [PATCH] D61869: Fix PR41843 - std::is_base_of should give correct result for incomplete unions

Marshall Clow via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon May 13 12:49:35 PDT 2019


mclow.lists created this revision.
mclow.lists added reviewers: EricWF, ldionne.
Herald added subscribers: dexonsmith, christof.

This relies on a fix that was recently checked into clang.

My plan is to land this in a week or so, once the bots that are running LLVM trunk have been updated.


https://reviews.llvm.org/D61869

Files:
  libcxx/test/std/utilities/meta/meta.rel/is_base_of.pass.cpp


Index: libcxx/test/std/utilities/meta/meta.rel/is_base_of.pass.cpp
===================================================================
--- libcxx/test/std/utilities/meta/meta.rel/is_base_of.pass.cpp
+++ libcxx/test/std/utilities/meta/meta.rel/is_base_of.pass.cpp
@@ -14,6 +14,15 @@
 
 #include "test_macros.h"
 
+//	Clang before v9 and apple-clang up to and including v10 do not
+//  report that unions are never base classes - nor can they have bases.
+//  See https://reviews.llvm.org/D61858
+#if (defined(TEST_COMPILER_APPLE_CLANG) && TEST_APPLE_CLANG_VER <= 1000)
+#define TEST_NO_INCOMPLETE_UNIONS
+#elif (defined(TEST_COMPILER_CLANG)     && TEST_CLANG_VER < 900)
+#define TEST_NO_INCOMPLETE_UNIONS
+#endif
+
 template <class T, class U>
 void test_is_base_of()
 {
@@ -39,6 +48,10 @@
 struct B1 : B {};
 struct B2 : B {};
 struct D : private B1, private B2 {};
+union U0;
+union U1 {};
+struct I0;
+struct I1 {};
 
 int main(int, char**)
 {
@@ -54,5 +67,61 @@
     test_is_not_base_of<B[3], D[3]>();
     test_is_not_base_of<int, int>();
 
+#ifndef TEST_NO_INCOMPLETE_UNIONS
+//	A union is never the base class of anything (including incomplete types)
+    test_is_not_base_of<U0, B>();
+    test_is_not_base_of<U0, B1>();
+    test_is_not_base_of<U0, B2>();
+    test_is_not_base_of<U0, D>();
+    test_is_not_base_of<U1, B>();
+    test_is_not_base_of<U1, B1>();
+    test_is_not_base_of<U1, B2>();
+    test_is_not_base_of<U1, D>();
+    test_is_not_base_of<U0, I0>();
+    test_is_not_base_of<U1, I1>();
+    test_is_not_base_of<U0, U1>();
+    test_is_not_base_of<U0, int>();
+    test_is_not_base_of<U1, int>();
+    test_is_not_base_of<I0, int>();
+    test_is_not_base_of<I1, int>();
+
+//	A union never has base classes (including incomplete types)
+    test_is_not_base_of<B,  U0>();
+    test_is_not_base_of<B1, U0>();
+    test_is_not_base_of<B2, U0>();
+    test_is_not_base_of<D,  U0>();
+    test_is_not_base_of<B,  U1>();
+    test_is_not_base_of<B1, U1>();
+    test_is_not_base_of<B2, U1>();
+    test_is_not_base_of<D,  U1>();
+    test_is_not_base_of<I0, U0>();
+    test_is_not_base_of<I1, U1>();
+    test_is_not_base_of<U1, U0>();
+    test_is_not_base_of<int, U0>();
+    test_is_not_base_of<int, U1>();
+    test_is_not_base_of<int, I0>();
+    test_is_not_base_of<int, I1>();
+#endif
+
+//	A scalar is never the base class of anything (including incomplete types)
+    test_is_not_base_of<int, B>();
+    test_is_not_base_of<int, B1>();
+    test_is_not_base_of<int, B2>();
+    test_is_not_base_of<int, D>();
+    test_is_not_base_of<int, I0>();
+    test_is_not_base_of<int, I1>();
+    test_is_not_base_of<int, U0>();
+    test_is_not_base_of<int, U1>();
+
+//	A scalar never has base classes (including incomplete types)
+    test_is_not_base_of<B,  int>();
+    test_is_not_base_of<B1, int>();
+    test_is_not_base_of<B2, int>();
+    test_is_not_base_of<D,  int>();
+    test_is_not_base_of<I0, int>();
+    test_is_not_base_of<I1, int>();
+    test_is_not_base_of<U0, int>();
+    test_is_not_base_of<U1, int>();
+
   return 0;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61869.199314.patch
Type: text/x-patch
Size: 3070 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190513/df55e1e9/attachment.bin>


More information about the libcxx-commits mailing list