From: Douglas Gregor Date: Wed, 18 Aug 2010 21:25:30 +0000 (+0000) Subject: There is no pointer conversion between to similar types (i.e., same X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4e938f57bdd68b3716a4476acf151cdd27bb8a50;p=clang There is no pointer conversion between to similar types (i.e., same type ignoring cv-qualifiers). These are qualification conversions. Fixes PR7934. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111428 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 8a0732702b..694975546c 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -1406,6 +1406,11 @@ bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType, QualType FromPointeeType = FromTypePtr->getPointeeType(); + // If the unqualified pointee types are the same, this can't be a + // pointer conversion, so don't do all of the work below. + if (Context.hasSameUnqualifiedType(FromPointeeType, ToPointeeType)) + return false; + // An rvalue of type "pointer to cv T," where T is an object type, // can be converted to an rvalue of type "pointer to cv void" (C++ // 4.10p2). diff --git a/test/SemaCXX/conversion-function.cpp b/test/SemaCXX/conversion-function.cpp index 73b78f414a..951cdb3f51 100644 --- a/test/SemaCXX/conversion-function.cpp +++ b/test/SemaCXX/conversion-function.cpp @@ -248,3 +248,25 @@ namespace PR7055 { Y f2(foo()); } + +namespace PR7934 { + typedef unsigned char uint8; + + struct MutablePtr { + MutablePtr() : ptr(0) {} + void *ptr; + + operator void*() { return ptr; } + + private: + operator uint8*() { return reinterpret_cast(ptr); } + operator const char*() const { return reinterpret_cast(ptr); } + }; + + void fake_memcpy(const void *); + + void use() { + MutablePtr ptr; + fake_memcpy(ptr); + } +}