[cfe-commits] r130605 - in /cfe/trunk: lib/AST/Type.cpp test/SemaCXX/type-traits.cpp
Chandler Carruth
chandlerc at gmail.com
Sat Apr 30 03:31:50 PDT 2011
Author: chandlerc
Date: Sat Apr 30 05:31:50 2011
New Revision: 130605
URL: http://llvm.org/viewvc/llvm-project?rev=130605&view=rev
Log:
Switch the type-trait like APIs on the AST to only check for incomplete
types after looking through arrays. Arrays with an unknown bound seem to
be specifically allowed in the library type traits in C++0x, and GCC's
builtin __is_trivial returns 'true' for the type 'int[]'. Now Clang
agrees with GCC about __is_trivial here.
Also hardens these methods against dependent types by just returning false.
Modified:
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/test/SemaCXX/type-traits.cpp
Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=130605&r1=130604&r2=130605&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Sat Apr 30 05:31:50 2011
@@ -869,7 +869,7 @@
}
bool Type::isLiteralType() const {
- if (isIncompleteType())
+ if (isDependentType())
return false;
// C++0x [basic.types]p10:
@@ -878,11 +878,16 @@
// -- an array of literal type
// Extension: variable arrays cannot be literal types, since they're
// runtime-sized.
- if (isArrayType() && !isConstantArrayType())
+ if (isVariableArrayType())
return false;
const Type *BaseTy = getBaseElementTypeUnsafe();
assert(BaseTy && "NULL element type");
+ // Return false for incomplete types after skipping any incomplete array
+ // types; those are expressly allowed by the standard and thus our API.
+ if (BaseTy->isIncompleteType())
+ return false;
+
// C++0x [basic.types]p10:
// A type is a literal type if it is:
// -- a scalar type; or
@@ -916,7 +921,7 @@
}
bool Type::isTrivialType() const {
- if (isIncompleteType())
+ if (isDependentType())
return false;
// C++0x [basic.types]p9:
@@ -925,6 +930,12 @@
// types.
const Type *BaseTy = getBaseElementTypeUnsafe();
assert(BaseTy && "NULL element type");
+
+ // Return false for incomplete types after skipping any incomplete array
+ // types which are expressly allowed by the standard and thus our API.
+ if (BaseTy->isIncompleteType())
+ return false;
+
if (BaseTy->isScalarType()) return true;
if (const RecordType *RT = BaseTy->getAs<RecordType>()) {
if (const CXXRecordDecl *ClassDecl =
@@ -944,7 +955,7 @@
}
bool Type::isStandardLayoutType() const {
- if (isIncompleteType())
+ if (isDependentType())
return false;
// C++0x [basic.types]p9:
@@ -953,6 +964,12 @@
// standard-layout types.
const Type *BaseTy = getBaseElementTypeUnsafe();
assert(BaseTy && "NULL element type");
+
+ // Return false for incomplete types after skipping any incomplete array
+ // types which are expressly allowed by the standard and thus our API.
+ if (BaseTy->isIncompleteType())
+ return false;
+
if (BaseTy->isScalarType()) return true;
if (const RecordType *RT = BaseTy->getAs<RecordType>()) {
if (const CXXRecordDecl *ClassDecl =
@@ -974,7 +991,7 @@
// isStandardLayoutType. We implement it dircetly to avoid redundant
// conversions from a type to a CXXRecordDecl.
bool Type::isCXX11PODType() const {
- if (isIncompleteType())
+ if (isDependentType())
return false;
// C++11 [basic.types]p9:
@@ -982,6 +999,12 @@
// versions of these types are collectively called trivial types.
const Type *BaseTy = getBaseElementTypeUnsafe();
assert(BaseTy && "NULL element type");
+
+ // Return false for incomplete types after skipping any incomplete array
+ // types which are expressly allowed by the standard and thus our API.
+ if (BaseTy->isIncompleteType())
+ return false;
+
if (BaseTy->isScalarType()) return true;
if (const RecordType *RT = BaseTy->getAs<RecordType>()) {
if (const CXXRecordDecl *ClassDecl =
Modified: cfe/trunk/test/SemaCXX/type-traits.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/type-traits.cpp?rev=130605&r1=130604&r2=130605&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/type-traits.cpp (original)
+++ cfe/trunk/test/SemaCXX/type-traits.cpp Sat Apr 30 05:31:50 2011
@@ -1429,12 +1429,14 @@
{ int arr[T(__is_trivial(POD))]; }
{ int arr[T(__is_trivial(Int))]; }
{ int arr[T(__is_trivial(IntAr))]; }
+ { int arr[T(__is_trivial(IntArNB))]; }
{ int arr[T(__is_trivial(Statics))]; }
{ int arr[T(__is_trivial(Empty))]; }
{ int arr[T(__is_trivial(EmptyUnion))]; }
{ int arr[T(__is_trivial(Union))]; }
{ int arr[T(__is_trivial(Derives))]; }
{ int arr[T(__is_trivial(DerivesAr))]; }
+ { int arr[T(__is_trivial(DerivesArNB))]; }
{ int arr[T(__is_trivial(DerivesEmpty))]; }
{ int arr[T(__is_trivial(HasFunc))]; }
{ int arr[T(__is_trivial(HasOp))]; }
@@ -1459,8 +1461,6 @@
{ int arr[F(__is_trivial(DerivesHasDest))]; }
{ int arr[F(__is_trivial(DerivesHasRef))]; }
{ int arr[F(__is_trivial(DerivesHasVirt))]; }
- { int arr[F(__is_trivial(IntArNB))]; }
- { int arr[F(__is_trivial(DerivesArNB))]; }
{ int arr[F(__is_trivial(void))]; }
{ int arr[F(__is_trivial(cvoid))]; }
}
More information about the cfe-commits
mailing list