[PATCH] D38075: Fix PR34668 - P0704R1 implementation is too permissive

Tim Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 20 03:24:13 PDT 2017


tcanens created this revision.
tcanens added a project: clang.

https://bugs.llvm.org/show_bug.cgi?id=34668

Pretty straightforward.


Repository:
  rL LLVM

https://reviews.llvm.org/D38075

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


Index: test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
===================================================================
--- test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
+++ test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
@@ -3,12 +3,15 @@
 struct X {
   void ref() & {}
   void cref() const& {}
+  void cvref() const volatile& {}
 };
 
 void test() {
   X{}.ref(); // expected-error{{cannot initialize object parameter of type 'X' with an expression of type 'X'}}
   X{}.cref(); // expected-no-error
+  X{}.cvref(); // expected-error{{cannot initialize object parameter of type 'const volatile X' with an expression of type 'X'}}
 
   (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}}
 }
Index: lib/Sema/SemaExprCXX.cpp
===================================================================
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -5183,7 +5183,7 @@
     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())
+        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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38075.115980.patch
Type: text/x-patch
Size: 1613 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170920/5d714a8b/attachment.bin>


More information about the cfe-commits mailing list