diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/AST/Type.cpp | 44 | ||||
-rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 17 |
2 files changed, 31 insertions, 30 deletions
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index 55f01e5822c..dbced252aa2 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -943,9 +943,36 @@ bool Type::isTrivialType() const { return false; } -// This is effectively the intersection of isTrivialType and hasStandardLayout. -// We implement it dircetly to avoid redundant conversions from a type to -// a CXXRecordDecl. +bool Type::isStandardLayoutType() const { + if (isIncompleteType()) + return false; + + // C++0x [basic.types]p9: + // Scalar types, standard-layout class types, arrays of such types, and + // cv-qualified versions of these types are collectively called + // standard-layout types. + const Type *BaseTy = getBaseElementTypeUnsafe(); + assert(BaseTy && "NULL element type"); + if (BaseTy->isScalarType()) return true; + if (const RecordType *RT = BaseTy->getAs<RecordType>()) { + if (const CXXRecordDecl *ClassDecl = + dyn_cast<CXXRecordDecl>(RT->getDecl())) + if (!ClassDecl->hasStandardLayout()) + return false; + + // Default to 'true' for non-C++ class types. + // FIXME: This is a bit dubious, but plain C structs should trivially meet + // all the requirements of standard layout classes. + return true; + } + + // No other types can match. + return false; +} + +// This is effectively the intersection of isTrivialType and +// isStandardLayoutType. We implement it dircetly to avoid redundant +// conversions from a type to a CXXRecordDecl. bool Type::isCXX11PODType() const { if (isIncompleteType()) return false; @@ -1448,17 +1475,6 @@ static uint64_t countBasesWithFields(QualType BaseType) { return BasesWithFields; } -bool RecordType::hasStandardLayout() const { - CXXRecordDecl *RD = cast<CXXRecordDecl>(getDecl()); - if (! RD) { - assert(cast<RecordDecl>(getDecl()) && - "RecordType does not have a corresponding RecordDecl"); - return true; - } - - return RD->hasStandardLayout(); -} - bool EnumType::classof(const TagType *TT) { return isa<EnumDecl>(TT->getDecl()); } diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index d975a155cd7..d87752081b3 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -2438,22 +2438,7 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, UnaryTypeTrait UTT, QualType T, case UTT_IsSigned: return T->isSignedIntegerType(); case UTT_IsStandardLayout: - // Error if T is an incomplete type. - if (Self.RequireCompleteType(KeyLoc, T, diag::err_incomplete_typeid)) - return false; - - // A standard layout type is: - // - a scalar type - // - an array of standard layout types - // - a standard layout class type: - if (EvaluateUnaryTypeTrait(Self, UTT_IsScalar, T, KeyLoc)) - return true; - if (EvaluateUnaryTypeTrait(Self, UTT_IsScalar, C.getBaseElementType(T), - KeyLoc)) - return true; - if (const RecordType *RT = C.getBaseElementType(T)->getAs<RecordType>()) - return RT->hasStandardLayout(); - return false; + return T->isStandardLayoutType(); case UTT_IsUnsigned: return T->isUnsignedIntegerType(); case UTT_IsVoid: |