summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaNamedCast.cpp
diff options
context:
space:
mode:
authorSebastian Redl <sebastian.redl@getdesigned.at>2009-05-10 18:38:11 +0000
committerSebastian Redl <sebastian.redl@getdesigned.at>2009-05-10 18:38:11 +0000
commit576fd424dfe20c855bc9a8ac5dbac0c4d11fd9ef (patch)
tree848feaf684633a0718f55a24ed033b266438c4cb /clang/lib/Sema/SemaNamedCast.cpp
parent9a627e60cdb55b69f99671ae98a9ce3a3af6a92a (diff)
downloadbcm5719-llvm-576fd424dfe20c855bc9a8ac5dbac0c4d11fd9ef.tar.gz
bcm5719-llvm-576fd424dfe20c855bc9a8ac5dbac0c4d11fd9ef.zip
Implement C++0x nullptr.
llvm-svn: 71405
Diffstat (limited to 'clang/lib/Sema/SemaNamedCast.cpp')
-rw-r--r--clang/lib/Sema/SemaNamedCast.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaNamedCast.cpp b/clang/lib/Sema/SemaNamedCast.cpp
index f5bef4a1f2d..e0b94a49ade 100644
--- a/clang/lib/Sema/SemaNamedCast.cpp
+++ b/clang/lib/Sema/SemaNamedCast.cpp
@@ -279,12 +279,26 @@ CheckReinterpretCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
return;
}
+ // See below for the enumeral issue.
+ if (SrcType->isNullPtrType() && DestType->isIntegralType() &&
+ !DestType->isEnumeralType()) {
+ // C++0x 5.2.10p4: A pointer can be explicitly converted to any integral
+ // type large enough to hold it. A value of std::nullptr_t can be
+ // converted to an integral type; the conversion has the same meaning
+ // and validity as a conversion of (void*)0 to the integral type.
+ if (Self.Context.getTypeSize(SrcType) >
+ Self.Context.getTypeSize(DestType)) {
+ Self.Diag(OpRange.getBegin(), diag::err_bad_reinterpret_cast_small_int)
+ << OrigDestType << DestRange;
+ }
+ return;
+ }
+
bool destIsPtr = DestType->isPointerType();
bool srcIsPtr = SrcType->isPointerType();
if (!destIsPtr && !srcIsPtr) {
- // Except for std::nullptr_t->integer, which is not supported yet, and
- // lvalue->reference, which is handled above, at least one of the two
- // arguments must be a pointer.
+ // Except for std::nullptr_t->integer and lvalue->reference, which are
+ // handled above, at least one of the two arguments must be a pointer.
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_generic)
<< "reinterpret_cast" << OrigDestType << OrigSrcType << OpRange;
return;
OpenPOWER on IntegriCloud