]> granicus.if.org Git - clang/commitdiff
Fix PR34668 - P0704R1 implementation is too permissive
authorNicolas Lesser <blitzrakete@gmail.com>
Fri, 13 Jul 2018 16:27:45 +0000 (16:27 +0000)
committerNicolas Lesser <blitzrakete@gmail.com>
Fri, 13 Jul 2018 16:27:45 +0000 (16:27 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337017 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprCXX.cpp
test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp

index 8ed795abbb7a56a412a1542a7e1b3ba7cf8d1b65..fbf572e39878cadac2fef7e48a465615f7206410 100644 (file)
@@ -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);
index 0bc40c81798384969d6b4b3cc59cdc1c7864f6fc..7c709d905f78830f0588a888212585be736ba53e 100644 (file)
@@ -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}}
 }