Skip to content

Commit

Permalink
Fix PR34668 - P0704R1 implementation is too permissive
Browse files Browse the repository at this point in the history
Summary:
https://bugs.llvm.org/show_bug.cgi?id=34668

Pretty straightforward.

Reviewers: rsmith, Rakete1111

Reviewed By: Rakete1111

Subscribers: Rakete1111, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D38075

llvm-svn: 337017
  • Loading branch information
Rakete1111 committed Jul 13, 2018
1 parent 3f7d209 commit 1ad0e9f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions clang/lib/Sema/SemaExprCXX.cpp
Expand Up @@ -5472,8 +5472,9 @@ QualType Sema::CheckPointerToMemberOperands(ExprResult &LHS, ExprResult &RHS,

case RQ_LValue:
if (!isIndirect && !LHS.get()->Classify(Context).isLValue()) {
// C++2a allows functions with ref-qualifier & if they are also 'const'.
if (Proto->isConst())
// C++2a allows functions with ref-qualifier & if their cv-qualifier-seq
// is (exactly) 'const'.
if (Proto->isConst() && !Proto->isVolatile())
Diag(Loc, getLangOpts().CPlusPlus2a
? diag::warn_cxx17_compat_pointer_to_const_ref_member_on_rvalue
: diag::ext_pointer_to_const_ref_member_on_rvalue);
Expand Down
3 changes: 3 additions & 0 deletions clang/test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
Expand Up @@ -3,12 +3,15 @@
struct X {
void ref() & {} // expected-note{{'ref' declared here}}
void cref() const& {}
void cvref() const volatile & {} // expected-note{{'cvref' declared here}}
};

void test() {
X{}.ref(); // expected-error{{'this' argument to member function 'ref' is an rvalue, but function has non-const lvalue ref-qualifier}}
X{}.cref(); // expected-no-error
X{}.cvref(); // expected-error{{'this' argument to member function 'cvref' is an rvalue, but function has non-const lvalue ref-qualifier}}

(X{}.*&X::ref)(); // expected-error-re{{pointer-to-member function type 'void (X::*)() {{.*}}&' can only be called on an lvalue}}
(X{}.*&X::cref)(); // expected-no-error
(X{}.*&X::cvref)(); // expected-error-re{{pointer-to-member function type 'void (X::*)() {{.*}}&' can only be called on an lvalue}}
}

0 comments on commit 1ad0e9f

Please sign in to comment.