aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancois Pichet <pichet2000@gmail.com>2011-05-11 22:13:54 +0000
committerFrancois Pichet <pichet2000@gmail.com>2011-05-11 22:13:54 +0000
commit30aff5b794599fac45cd8716412caf32f29ccb7e (patch)
tree317e3f382fcee3294a335d09ba41cce53085ad22
parent225c5dda5a9c85b7bee5d955875e239f70924f74 (diff)
In Microsoft mode, allow conversion from pointer to integral type no matter what size the integral type is. Necessary to parse MFC code.
Example: void f(char *ptr) { char var = (char)ptr; } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131201 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaCXXCast.cpp8
-rw-r--r--test/SemaCXX/MicrosoftExtensions.cpp8
2 files changed, 13 insertions, 3 deletions
diff --git a/lib/Sema/SemaCXXCast.cpp b/lib/Sema/SemaCXXCast.cpp
index 2ea3b46829..31a5f92dac 100644
--- a/lib/Sema/SemaCXXCast.cpp
+++ b/lib/Sema/SemaCXXCast.cpp
@@ -1514,9 +1514,11 @@ static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr,
if (DestType->isIntegralType(Self.Context)) {
assert(srcIsPtr && "One type must be a pointer");
// C++ 5.2.10p4: A pointer can be explicitly converted to any integral
- // type large enough to hold it.
- if (Self.Context.getTypeSize(SrcType) >
- Self.Context.getTypeSize(DestType)) {
+ // type large enough to hold it; except in Microsoft mode, where the
+ // integral type size doesn't matter.
+ if ((Self.Context.getTypeSize(SrcType) >
+ Self.Context.getTypeSize(DestType)) &&
+ !Self.getLangOptions().Microsoft) {
msg = diag::err_bad_reinterpret_cast_small_int;
return TC_Failed;
}
diff --git a/test/SemaCXX/MicrosoftExtensions.cpp b/test/SemaCXX/MicrosoftExtensions.cpp
index d1da0f7db0..88e3922670 100644
--- a/test/SemaCXX/MicrosoftExtensions.cpp
+++ b/test/SemaCXX/MicrosoftExtensions.cpp
@@ -189,3 +189,11 @@ void function_to_voidptr_conv() {
void *a2 = &function_prototype;
void *a3 = function_ptr;
}
+
+
+void pointer_to_integral_type_conv(char* ptr) {
+ char ch = (char)ptr;
+ short sh = (short)ptr;
+ ch = (char)ptr;
+ sh = (short)ptr;
+}