]> granicus.if.org Git - clang/commitdiff
27037: Use correct CVR qualifier on an upcast on method pointer call
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 9 Jun 2017 22:25:28 +0000 (22:25 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 9 Jun 2017 22:25:28 +0000 (22:25 +0000)
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

lib/Sema/SemaExprCXX.cpp
test/SemaCXX/PR27037.cpp [new file with mode: 0644]

index 34b10aec8807c2f2775f5f657d0bc17e927674de..00a4b39f14236c3098232e3305e17218f10ec923 100644 (file)
@@ -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 (file)
index 0000000..422de0e
--- /dev/null
@@ -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}}
+}