r311744 - [c++2a] P0704R1: Allow pointers to const& member functions to be called on rvalues.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 24 18:47:55 PDT 2017
Author: rsmith
Date: Thu Aug 24 18:47:55 2017
New Revision: 311744
URL: http://llvm.org/viewvc/llvm-project?rev=311744&view=rev
Log:
[c++2a] P0704R1: Allow pointers to const& member functions to be called on rvalues.
Patch by Blitz Rakete!
Added:
cfe/trunk/test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/www/cxx_status.html
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=311744&r1=311743&r2=311744&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Aug 24 18:47:55 2017
@@ -4088,6 +4088,13 @@ def err_pointer_to_member_call_drops_qua
def err_pointer_to_member_oper_value_classify: Error<
"pointer-to-member function type %0 can only be called on an "
"%select{rvalue|lvalue}1">;
+def ext_pointer_to_const_ref_member_on_rvalue : Extension<
+ "invoking a pointer to a 'const &' member function on an rvalue is a C++2a extension">,
+ InGroup<CXX2a>, SFINAEFailure;
+def warn_cxx17_compat_pointer_to_const_ref_member_on_rvalue : Warning<
+ "invoking a pointer to a 'const &' member function on an rvalue is "
+ "incompatible with C++ standards before C++2a">,
+ InGroup<CXXPre2aCompatPedantic>, DefaultIgnore;
def ext_ms_deref_template_argument: ExtWarn<
"non-type template argument containing a dereference operation is a "
"Microsoft extension">, InGroup<MicrosoftTemplate>;
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=311744&r1=311743&r2=311744&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Aug 24 18:47:55 2017
@@ -5175,9 +5175,16 @@ QualType Sema::CheckPointerToMemberOpera
break;
case RQ_LValue:
- if (!isIndirect && !LHS.get()->Classify(Context).isLValue())
- Diag(Loc, diag::err_pointer_to_member_oper_value_classify)
- << RHSType << 1 << LHS.get()->getSourceRange();
+ if (!isIndirect && !LHS.get()->Classify(Context).isLValue()) {
+ // C++2a allows functions with ref-qualifier & if they are also 'const'.
+ if (Proto->isConst())
+ Diag(Loc, getLangOpts().CPlusPlus2a
+ ? diag::warn_cxx17_compat_pointer_to_const_ref_member_on_rvalue
+ : diag::ext_pointer_to_const_ref_member_on_rvalue);
+ else
+ Diag(Loc, diag::err_pointer_to_member_oper_value_classify)
+ << RHSType << 1 << LHS.get()->getSourceRange();
+ }
break;
case RQ_RValue:
Added: cfe/trunk/test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp?rev=311744&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp (added)
+++ cfe/trunk/test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp Thu Aug 24 18:47:55 2017
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++2a %s -verify
+
+struct X {
+ void ref() & {}
+ void cref() const& {}
+};
+
+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{}.*&X::ref)(); // expected-error{{pointer-to-member function type 'void (X::*)() &' can only be called on an lvalue}}
+ (X{}.*&X::cref)(); // expected-no-error
+}
Modified: cfe/trunk/www/cxx_status.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_status.html?rev=311744&r1=311743&r2=311744&view=diff
==============================================================================
--- cfe/trunk/www/cxx_status.html (original)
+++ cfe/trunk/www/cxx_status.html Thu Aug 24 18:47:55 2017
@@ -802,7 +802,7 @@ as the draft C++2a standard evolves.
<tr>
<td><tt>const&</tt>-qualified pointers to members</td>
<td><a href="http://wg21.link/p0704r1">P0704R1</a></td>
- <td class="none" align="center">No</td>
+ <td class="svn" align="center">SVN</td>
</tr>
<tr>
<td>Allow <i>lambda-capture</i> <tt>[=, this]</tt></td>
More information about the cfe-commits
mailing list