forked from OSchip/llvm-project
[Sema] Objective-C++ support for type trait __is_base_of
rdar://24308607 Differential revision: https://reviews.llvm.org/D32891 llvm-svn: 302695
This commit is contained in:
parent
896cbc40ad
commit
07f8c439b3
|
@ -4720,10 +4720,24 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, QualType LhsT,
|
|||
// 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));
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
|
||||
|
||||
@interface NSObj
|
||||
@end
|
||||
|
||||
@interface NSChild : NSObj
|
||||
@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), "");
|
||||
|
||||
@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), "");
|
Loading…
Reference in New Issue