summaryrefslogtreecommitdiffstats
path: root/lib/Sema/SemaCast.cpp
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2013-06-06 09:16:36 +0000
committerHans Wennborg <hans@hanshq.net>2013-06-06 09:16:36 +0000
commit649c6c50fd3dd13577071b26fec4495f7538d923 (patch)
tree0b52d6bb889101e338208f14945817cdc74caaee /lib/Sema/SemaCast.cpp
parent9acb8b4355028887e8cc4aa8f683aceee021a62b (diff)
Disallow reinterpret_cast from pointer to bool on Windows
This became allowed by accident in r131201, but triggers an assert. That patch added an exception to allow conversion from pointers to narrow integral types for MSVC compatibility. However, a pointer can already be converted to bool in a civilized manner; allowing conversion via reinterpret_cast is a bad idea. Fixes PR16222. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183394 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaCast.cpp')
-rw-r--r--lib/Sema/SemaCast.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/Sema/SemaCast.cpp b/lib/Sema/SemaCast.cpp
index 3f0a1a36e4..b4e7113319 100644
--- a/lib/Sema/SemaCast.cpp
+++ b/lib/Sema/SemaCast.cpp
@@ -1813,10 +1813,12 @@ static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr,
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; except in Microsoft mode, where the
- // integral type size doesn't matter.
+ // integral type size doesn't matter (except we don't allow bool).
+ bool MicrosoftException = Self.getLangOpts().MicrosoftExt &&
+ !DestType->isBooleanType();
if ((Self.Context.getTypeSize(SrcType) >
Self.Context.getTypeSize(DestType)) &&
- !Self.getLangOpts().MicrosoftExt) {
+ !MicrosoftException) {
msg = diag::err_bad_reinterpret_cast_small_int;
return TC_Failed;
}