mclow.lists created this revision. mclow.lists added reviewers: rsmith, t.p.northover, EricWF, ldionne. mclow.lists added a project: clang. Herald added a subscriber: dexonsmith.
Unions are never base classes, and never have base classes. It doesn't matter if they are complete or not. See http://llvm.org/PR41843 https://reviews.llvm.org/D61858 Files: clang/lib/Sema/SemaExprCXX.cpp clang/test/SemaCXX/type-traits.cpp 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>))]; } { int arr[F(__is_base_of(Base, UndefinedTemp<int>))]; } // expected-error {{implicit instantiation of undefined template 'UndefinedTemp<int>'}} + { 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<Base, Derived>(); isBaseOfF<Derived, Base>(); 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>))]; } { int arr[F(__is_base_of(Base, UndefinedTemp<int>))]; } // expected-error {{implicit instantiation of undefined template 'UndefinedTemp<int>'}} + { 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<Base, Derived>(); isBaseOfF<Derived, Base>(); 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits