[cfe-commits] r105494 - in /cfe/trunk: lib/Sema/SemaCXXCast.cpp test/SemaCXX/reinterpret-cast.cpp
Anders Carlsson
andersca at mac.com
Fri Jun 4 15:47:55 PDT 2010
Author: andersca
Date: Fri Jun 4 17:47:55 2010
New Revision: 105494
URL: http://llvm.org/viewvc/llvm-project?rev=105494&view=rev
Log:
When deciding whether reinterpret_cast casts away constness we need to look at array qualifiers. Fixes rdar://problem/8018292.
Modified:
cfe/trunk/lib/Sema/SemaCXXCast.cpp
cfe/trunk/test/SemaCXX/reinterpret-cast.cpp
Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=105494&r1=105493&r2=105494&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Fri Jun 4 17:47:55 2010
@@ -257,8 +257,13 @@
// Find the qualifications.
while (UnwrapDissimilarPointerTypes(UnwrappedSrcType, UnwrappedDestType)) {
- cv1.push_back(UnwrappedSrcType.getQualifiers());
- cv2.push_back(UnwrappedDestType.getQualifiers());
+ Qualifiers SrcQuals;
+ Self.Context.getUnqualifiedArrayType(UnwrappedSrcType, SrcQuals);
+ cv1.push_back(SrcQuals);
+
+ Qualifiers DestQuals;
+ Self.Context.getUnqualifiedArrayType(UnwrappedDestType, DestQuals);
+ cv2.push_back(DestQuals);
}
assert(cv1.size() > 0 && "Must have at least one pointer level.");
Modified: cfe/trunk/test/SemaCXX/reinterpret-cast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/reinterpret-cast.cpp?rev=105494&r1=105493&r2=105494&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/reinterpret-cast.cpp (original)
+++ cfe/trunk/test/SemaCXX/reinterpret-cast.cpp Fri Jun 4 17:47:55 2010
@@ -91,8 +91,20 @@
(void)reinterpret_cast<int structure::*>(0); // expected-error {{reinterpret_cast from 'int' to 'int structure::*' is not allowed}}
}
+namespace PR5545 {
// PR5545
class A;
class B;
void (A::*a)();
void (B::*b)() = reinterpret_cast<void (B::*)()>(a);
+}
+
+// <rdar://problem/8018292>
+void const_arrays() {
+ typedef char STRING[10];
+ const STRING *s;
+ const char *c;
+
+ (void)reinterpret_cast<char *>(s); // expected-error {{reinterpret_cast from 'STRING const *' (aka 'char const (*)[10]') to 'char *' casts away constness}}
+ (void)reinterpret_cast<const STRING *>(c);
+}
More information about the cfe-commits
mailing list