From: Richard Smith Date: Fri, 9 Jun 2017 22:25:28 +0000 (+0000) Subject: 27037: Use correct CVR qualifier on an upcast on method pointer call X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bc18067b2dbf059e09e10e8b2417361857c52ba2;p=clang 27037: Use correct CVR qualifier on an upcast on method pointer call Patch by Taiju Tsuiki! Differential Revision: https://reviews.llvm.org/D33875 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305126 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 34b10aec88..00a4b39f14 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -5106,7 +5106,9 @@ QualType Sema::CheckPointerToMemberOperands(ExprResult &LHS, ExprResult &RHS, return QualType(); // Cast LHS to type of use. - QualType UseType = isIndirect ? Context.getPointerType(Class) : Class; + QualType UseType = Context.getQualifiedType(Class, LHSType.getQualifiers()); + if (isIndirect) + UseType = Context.getPointerType(UseType); ExprValueKind VK = isIndirect ? VK_RValue : LHS.get()->getValueKind(); LHS = ImpCastExprToType(LHS.get(), UseType, CK_DerivedToBase, VK, &BasePath); diff --git a/test/SemaCXX/PR27037.cpp b/test/SemaCXX/PR27037.cpp new file mode 100644 index 0000000000..422de0e637 --- /dev/null +++ b/test/SemaCXX/PR27037.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct A { + void f(); +}; + +struct B : A {}; + +void m() { + const B b; + (b.*&B::f)(); // expected-error{{drops 'const' qualifier}} + ((&b)->*&B::f)(); // expected-error{{drops 'const' qualifier}} +}