[cfe-commits] r90361 - in /cfe/trunk: include/clang/AST/Type.h include/clang/Basic/TokenKinds.def include/clang/Basic/TypeTraits.h lib/AST/ExprCXX.cpp lib/AST/Type.cpp lib/Parse/ParseExpr.cpp lib/Parse/ParseExprCXX.cpp test/SemaCXX/literal-type.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Wed Dec 2 16:13:20 PST 2009
Author: cornedbee
Date: Wed Dec 2 18:13:20 2009
New Revision: 90361
URL: http://llvm.org/viewvc/llvm-project?rev=90361&view=rev
Log:
Introduce the notion of literal types, as specified in C++0x.
Added:
cfe/trunk/test/SemaCXX/literal-type.cpp
Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/include/clang/Basic/TypeTraits.h
cfe/trunk/lib/AST/ExprCXX.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=90361&r1=90360&r2=90361&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Wed Dec 2 18:13:20 2009
@@ -791,6 +791,10 @@
/// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10).
bool isPODType() const;
+ /// isLiteralType - Return true if this is a literal type
+ /// (C++0x [basic.types]p10)
+ bool isLiteralType() const;
+
/// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array
/// types that have a non-constant expression. This does not include "[]".
bool isVariablyModifiedType() const;
Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=90361&r1=90360&r2=90361&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Wed Dec 2 18:13:20 2009
@@ -324,6 +324,8 @@
KEYWORD(__is_pod , KEYCXX)
KEYWORD(__is_polymorphic , KEYCXX)
KEYWORD(__is_union , KEYCXX)
+// Tentative name - there's no implementation of std::is_literal_type yet.
+KEYWORD(__is_literal , KEYCXX)
// FIXME: Add MS's traits, too.
// Apple Extension.
Modified: cfe/trunk/include/clang/Basic/TypeTraits.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TypeTraits.h?rev=90361&r1=90360&r2=90361&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TypeTraits.h (original)
+++ cfe/trunk/include/clang/Basic/TypeTraits.h Wed Dec 2 18:13:20 2009
@@ -32,7 +32,8 @@
UTT_IsEnum,
UTT_IsPOD,
UTT_IsPolymorphic,
- UTT_IsUnion
+ UTT_IsUnion,
+ UTT_IsLiteral
};
}
Modified: cfe/trunk/lib/AST/ExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=90361&r1=90360&r2=90361&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Wed Dec 2 18:13:20 2009
@@ -199,6 +199,7 @@
switch(UTT) {
default: assert(false && "Unknown type trait or not implemented");
case UTT_IsPOD: return QueriedType->isPODType();
+ case UTT_IsLiteral: return QueriedType->isLiteralType();
case UTT_IsClass: // Fallthrough
case UTT_IsUnion:
if (const RecordType *Record = QueriedType->getAs<RecordType>()) {
Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=90361&r1=90360&r2=90361&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Wed Dec 2 18:13:20 2009
@@ -639,6 +639,40 @@
}
}
+bool Type::isLiteralType() const {
+ if (isIncompleteType())
+ return false;
+
+ // C++0x [basic.types]p10:
+ // A type is a literal type if it is:
+ switch (CanonicalType->getTypeClass()) {
+ // We're whitelisting
+ default: return false;
+
+ // -- a scalar type
+ case Builtin:
+ case Complex:
+ case Pointer:
+ case MemberPointer:
+ case Vector:
+ case ExtVector:
+ case ObjCObjectPointer:
+ case Enum:
+ return true;
+
+ // -- a class type with ...
+ case Record:
+ // FIXME: Do the tests
+ return false;
+
+ // -- an array of literal type
+ // Extension: variable arrays cannot be literal types, since they're
+ // runtime-sized.
+ case ConstantArray:
+ return cast<ArrayType>(CanonicalType)->getElementType()->isLiteralType();
+ }
+}
+
bool Type::isPromotableIntegerType() const {
if (const BuiltinType *BT = getAs<BuiltinType>())
switch (BT->getKind()) {
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=90361&r1=90360&r2=90361&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Wed Dec 2 18:13:20 2009
@@ -826,6 +826,7 @@
case tok::kw___is_empty:
case tok::kw___is_polymorphic:
case tok::kw___is_abstract:
+ case tok::kw___is_literal:
case tok::kw___has_trivial_constructor:
case tok::kw___has_trivial_copy:
case tok::kw___has_trivial_assign:
Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=90361&r1=90360&r2=90361&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Wed Dec 2 18:13:20 2009
@@ -1459,6 +1459,7 @@
case tok::kw___is_pod: return UTT_IsPOD;
case tok::kw___is_polymorphic: return UTT_IsPolymorphic;
case tok::kw___is_union: return UTT_IsUnion;
+ case tok::kw___is_literal: return UTT_IsLiteral;
}
}
Added: cfe/trunk/test/SemaCXX/literal-type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/literal-type.cpp?rev=90361&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/literal-type.cpp (added)
+++ cfe/trunk/test/SemaCXX/literal-type.cpp Wed Dec 2 18:13:20 2009
@@ -0,0 +1,10 @@
+// RUN: clang-cc -fsyntax-only -verify -std=c++0x %s
+
+static_assert(__is_literal(int), "fail");
+static_assert(__is_literal(void*), "fail");
+enum E { E1 };
+static_assert(__is_literal(E), "fail");
+static_assert(__is_literal(decltype(E1)), "fail");
+typedef int IAR[10];
+static_assert(__is_literal(IAR), "fail");
+// FIXME: Records
More information about the cfe-commits
mailing list