r302695 - [Sema] Objective-C++ support for type trait __is_base_of

Erik Pilkington via cfe-commits cfe-commits at lists.llvm.org
Wed May 10 10:18:56 PDT 2017


Author: epilk
Date: Wed May 10 12:18:56 2017
New Revision: 302695

URL: http://llvm.org/viewvc/llvm-project?rev=302695&view=rev
Log:
[Sema] Objective-C++ support for type trait __is_base_of

rdar://24308607

Differential revision: https://reviews.llvm.org/D32891

Added:
    cfe/trunk/test/SemaObjCXX/is-base-of.mm
Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=302695&r1=302694&r2=302695&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed May 10 12:18:56 2017
@@ -4720,10 +4720,24 @@ static bool EvaluateBinaryTypeTrait(Sema
     // regard to cv-qualifiers.
 
     const RecordType *lhsRecord = LhsT->getAs<RecordType>();
-    if (!lhsRecord) return false;
-
     const RecordType *rhsRecord = RhsT->getAs<RecordType>();
-    if (!rhsRecord) return false;
+    if (!rhsRecord || !lhsRecord) {
+      const ObjCObjectType *LHSObjTy = LhsT->getAs<ObjCObjectType>();
+      const ObjCObjectType *RHSObjTy = RhsT->getAs<ObjCObjectType>();
+      if (!LHSObjTy || !RHSObjTy)
+        return false;
+
+      ObjCInterfaceDecl *BaseInterface = LHSObjTy->getInterface();
+      ObjCInterfaceDecl *DerivedInterface = RHSObjTy->getInterface();
+      if (!BaseInterface || !DerivedInterface)
+        return false;
+
+      if (Self.RequireCompleteType(
+              KeyLoc, RhsT, diag::err_incomplete_type_used_in_type_trait_expr))
+        return false;
+
+      return BaseInterface->isSuperClassOf(DerivedInterface);
+    }
 
     assert(Self.Context.hasSameUnqualifiedType(LhsT, RhsT)
              == (lhsRecord == rhsRecord));

Added: cfe/trunk/test/SemaObjCXX/is-base-of.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/is-base-of.mm?rev=302695&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/is-base-of.mm (added)
+++ cfe/trunk/test/SemaObjCXX/is-base-of.mm Wed May 10 12:18:56 2017
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+ at interface NSObj
+ at end
+
+ at interface NSChild : NSObj
+ at end
+
+static_assert(__is_base_of(NSObj, NSChild), "");
+static_assert(!__is_base_of(NSChild, NSObj), "");
+
+static_assert(__is_base_of(NSObj, NSObj), "");
+
+static_assert(!__is_base_of(NSObj *, NSChild *), "");
+static_assert(!__is_base_of(NSChild *, NSObj *), "");
+
+static_assert(__is_base_of(const volatile NSObj, NSChild), "");
+static_assert(__is_base_of(NSObj, const volatile NSChild), "");
+
+ at class NSForward; // expected-note{{forward declaration of class}}
+
+static_assert(!__is_base_of(NSForward, NSObj), "");
+static_assert(!__is_base_of(NSObj, NSForward), ""); // expected-error{{incomplete type 'NSForward'}}
+
+static_assert(!__is_base_of(id, NSObj), "");




More information about the cfe-commits mailing list