tzik updated this revision to Diff 101536. tzik added a comment. Cover indirect case and non-CVR qualifiers
https://reviews.llvm.org/D33875 Files: lib/Sema/SemaExprCXX.cpp test/SemaCXX/PR27037.cpp Index: test/SemaCXX/PR27037.cpp =================================================================== --- /dev/null +++ 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}} +} Index: lib/Sema/SemaExprCXX.cpp =================================================================== --- lib/Sema/SemaExprCXX.cpp +++ lib/Sema/SemaExprCXX.cpp @@ -5104,7 +5104,9 @@ 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);
Index: test/SemaCXX/PR27037.cpp =================================================================== --- /dev/null +++ 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}} +} Index: lib/Sema/SemaExprCXX.cpp =================================================================== --- lib/Sema/SemaExprCXX.cpp +++ lib/Sema/SemaExprCXX.cpp @@ -5104,7 +5104,9 @@ 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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits