From 52647c63c3cbdf0c87fe8db3ef6f475bfd49725d Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Fri, 4 Jun 2010 22:47:55 +0000 Subject: [PATCH] When deciding whether reinterpret_cast casts away constness we need to look at array qualifiers. Fixes rdar://problem/8018292. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105494 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaCXXCast.cpp | 9 +++++++-- test/SemaCXX/reinterpret-cast.cpp | 12 ++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaCXXCast.cpp b/lib/Sema/SemaCXXCast.cpp index 9b95552554..5485bb3e17 100644 --- a/lib/Sema/SemaCXXCast.cpp +++ b/lib/Sema/SemaCXXCast.cpp @@ -257,8 +257,13 @@ CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType) { // 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."); diff --git a/test/SemaCXX/reinterpret-cast.cpp b/test/SemaCXX/reinterpret-cast.cpp index 45d41e8460..f054e528d2 100644 --- a/test/SemaCXX/reinterpret-cast.cpp +++ b/test/SemaCXX/reinterpret-cast.cpp @@ -91,8 +91,20 @@ void memptrs() (void)reinterpret_cast(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(a); +} + +// +void const_arrays() { + typedef char STRING[10]; + const STRING *s; + const char *c; + + (void)reinterpret_cast(s); // expected-error {{reinterpret_cast from 'STRING const *' (aka 'char const (*)[10]') to 'char *' casts away constness}} + (void)reinterpret_cast(c); +} -- 2.40.0