Index: clang/lib/Sema/SemaExprCXX.cpp =================================================================== --- clang/lib/Sema/SemaExprCXX.cpp +++ clang/lib/Sema/SemaExprCXX.cpp @@ -5118,8 +5118,15 @@ assert(Self.Context.hasSameUnqualifiedType(LhsT, RhsT) == (lhsRecord == rhsRecord)); + // Unions are never base classes, and never have base classes. + // It doesn't matter if they are complete or not. See PR#41843 + if (lhsRecord && lhsRecord->getDecl()->isUnion()) + return false; + if (rhsRecord && rhsRecord->getDecl()->isUnion()) + return false; + if (lhsRecord == rhsRecord) - return !lhsRecord->getDecl()->isUnion(); + return true; // C++0x [meta.rel]p2: // If Base and Derived are class types and are different types Index: clang/test/SemaCXX/type-traits.cpp =================================================================== --- clang/test/SemaCXX/type-traits.cpp +++ clang/test/SemaCXX/type-traits.cpp @@ -14,6 +14,7 @@ enum Enum { EV }; struct POD { Enum e; int i; float f; NonPOD* p; }; struct Empty {}; +struct IncompleteStruct; typedef Empty EmptyAr[10]; typedef Empty EmptyArNB[]; typedef Empty EmptyArMB[1][2]; @@ -1915,6 +1916,20 @@ { int arr[F(__is_base_of(Base, NonderivedTemp))]; } { int arr[F(__is_base_of(Base, UndefinedTemp))]; } // expected-error {{implicit instantiation of undefined template 'UndefinedTemp'}} + { int arr[F(__is_base_of(IncompleteUnion, IncompleteUnion))]; } + { int arr[F(__is_base_of(Union, IncompleteUnion))]; } + { int arr[F(__is_base_of(IncompleteUnion, Union))]; } + { int arr[F(__is_base_of(IncompleteStruct, IncompleteUnion))]; } + { int arr[F(__is_base_of(IncompleteUnion, IncompleteStruct))]; } + { int arr[F(__is_base_of(Empty, IncompleteUnion))]; } + { int arr[F(__is_base_of(IncompleteUnion, Empty))]; } + { int arr[F(__is_base_of(int, IncompleteUnion))]; } + { int arr[F(__is_base_of(IncompleteUnion, int))]; } + { int arr[F(__is_base_of(Empty, Union))]; } + { int arr[F(__is_base_of(Union, Empty))]; } + { int arr[F(__is_base_of(int, Empty))]; } + { int arr[F(__is_base_of(Union, int))]; } + isBaseOfT(); isBaseOfF();