[PATCH] D32891: [Sema][ObjC++] Objective-C++ support for __is_base_of(B, D)
Phabricator via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 10 10:32:18 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL302695: [Sema] Objective-C++ support for type trait __is_base_of (authored by epilk).
Changed prior to commit:
https://reviews.llvm.org/D32891?vs=97905&id=98490#toc
Repository:
rL LLVM
https://reviews.llvm.org/D32891
Files:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/SemaObjCXX/is-base-of.mm
Index: cfe/trunk/lib/Sema/SemaExprCXX.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp
@@ -4720,10 +4720,24 @@
// 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));
Index: cfe/trunk/test/SemaObjCXX/is-base-of.mm
===================================================================
--- cfe/trunk/test/SemaObjCXX/is-base-of.mm
+++ cfe/trunk/test/SemaObjCXX/is-base-of.mm
@@ -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), "");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32891.98490.patch
Type: text/x-patch
Size: 2223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170510/7fa38dd7/attachment.bin>
More information about the cfe-commits
mailing list