r360614 - Make more friendly with unions. Reviewed as https://reviews.llvm.org/D61858
Marshall Clow via cfe-commits
cfe-commits at lists.llvm.org
Mon May 13 12:29:23 PDT 2019
Author: marshall
Date: Mon May 13 12:29:23 2019
New Revision: 360614
URL: http://llvm.org/viewvc/llvm-project?rev=360614&view=rev
Log:
Make more friendly with unions. Reviewed as https://reviews.llvm.org/D61858
Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/SemaCXX/type-traits.cpp
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=360614&r1=360613&r2=360614&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon May 13 12:29:23 2019
@@ -5118,8 +5118,15 @@ static bool EvaluateBinaryTypeTrait(Sema
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
Modified: cfe/trunk/test/SemaCXX/type-traits.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/type-traits.cpp?rev=360614&r1=360613&r2=360614&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/type-traits.cpp (original)
+++ cfe/trunk/test/SemaCXX/type-traits.cpp Mon May 13 12:29:23 2019
@@ -14,6 +14,7 @@ typedef NonPOD NonPODArMB[10][2];
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 @@ void is_base_of() {
{ 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>();
More information about the cfe-commits
mailing list