summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
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
commit15439bcf79decf81f94bfaf2e4b39167bf954b18 (patch)
tree4af47a5933186eaf32c505ef5599039c8507666b /clang/lib/Sema
parent6dcecb6b33ee04a93ef4f94e8597f9b8679d1c5d (diff)
downloadbcm5719-llvm-15439bcf79decf81f94bfaf2e4b39167bf954b18.tar.gz
bcm5719-llvm-15439bcf79decf81f94bfaf2e4b39167bf954b18.zip
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. llvm-svn: 183394
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaCast.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index 3f0a1a36e46..b4e71133197 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/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;
}
OpenPOWER on IntegriCloud