Commit 681f18d1 by Jakub Jelinek Committed by Jakub Jelinek

P0704R1 - fixing const-qualified pointers to members

	P0704R1 - fixing const-qualified pointers to members
	* typeck2.c (build_m_component_ref): For -std=c++2a allow
	pointer to const & qualified method on rvalue.

	* g++.dg/cpp2a/ptrmem1.C: New test.

From-SVN: r253494
parent 9bc3f420
2017-10-06 Jakub Jelinek <jakub@redhat.com>
P0704R1 - fixing const-qualified pointers to members
* typeck2.c (build_m_component_ref): For -std=c++2a allow
pointer to const & qualified method on rvalue.
2017-10-06 Nathan Sidwell <nathan@acm.org> 2017-10-06 Nathan Sidwell <nathan@acm.org>
Use hash_table for extern "C" names Use hash_table for extern "C" names
......
...@@ -1908,9 +1908,10 @@ build_m_component_ref (tree datum, tree component, tsubst_flags_t complain) ...@@ -1908,9 +1908,10 @@ build_m_component_ref (tree datum, tree component, tsubst_flags_t complain)
{ {
/* 5.5/6: In a .* expression whose object expression is an rvalue, the /* 5.5/6: In a .* expression whose object expression is an rvalue, the
program is ill-formed if the second operand is a pointer to member program is ill-formed if the second operand is a pointer to member
function with ref-qualifier &. In a .* expression whose object function with ref-qualifier & (for C++2A: unless its cv-qualifier-seq
expression is an lvalue, the program is ill-formed if the second is const). In a .* expression whose object expression is an lvalue,
operand is a pointer to member function with ref-qualifier &&. */ the program is ill-formed if the second operand is a pointer to member
function with ref-qualifier &&. */
if (FUNCTION_REF_QUALIFIED (type)) if (FUNCTION_REF_QUALIFIED (type))
{ {
bool lval = lvalue_p (datum); bool lval = lvalue_p (datum);
...@@ -1921,7 +1922,12 @@ build_m_component_ref (tree datum, tree component, tsubst_flags_t complain) ...@@ -1921,7 +1922,12 @@ build_m_component_ref (tree datum, tree component, tsubst_flags_t complain)
ptrmem_type); ptrmem_type);
return error_mark_node; return error_mark_node;
} }
else if (!lval && !FUNCTION_RVALUE_QUALIFIED (type)) else if (!lval
&& !FUNCTION_RVALUE_QUALIFIED (type)
&& (cxx_dialect < cxx2a
|| ((type_memfn_quals (type)
& (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE))
!= TYPE_QUAL_CONST)))
{ {
if (complain & tf_error) if (complain & tf_error)
error ("pointer-to-member-function type %qT requires an lvalue", error ("pointer-to-member-function type %qT requires an lvalue",
......
2017-10-06 Jakub Jelinek <jakub@redhat.com>
P0704R1 - fixing const-qualified pointers to members
* g++.dg/cpp2a/ptrmem1.C: New test.
2017-10-06 Martin Liska <mliska@suse.cz> 2017-10-06 Martin Liska <mliska@suse.cz>
* c-c++-common/ubsan/ptr-overflow-sanitization-1.c: New test. * c-c++-common/ubsan/ptr-overflow-sanitization-1.c: New test.
......
// P0704R1
// { dg-do compile { target c++11 } }
struct S {
void ref() & {}
void cref() const& {}
void vref() volatile & {}
void cvref() const volatile & {}
};
void
foo ()
{
S{}.ref(); // { dg-error "argument discards qualifiers" }
S{}.cref();
S{}.vref(); // { dg-error "argument discards qualifiers" }
S{}.cvref(); // { dg-error "argument discards qualifiers" }
(S{}.*&S::ref)(); // { dg-error "pointer-to-member-function type 'void \\(S::\\*\\)\\(\\) &' requires an lvalue" }
(S{}.*&S::cref)(); // { dg-error "pointer-to-member-function type 'void \\(S::\\*\\)\\(\\) const &' requires an lvalue" "" { target c++17_down } }
(S{}.*&S::vref)(); // { dg-error "pointer-to-member-function type 'void \\(S::\\*\\)\\(\\) volatile &' requires an lvalue" }
(S{}.*&S::cvref)(); // { dg-error "pointer-to-member-function type 'void \\(S::\\*\\)\\(\\) const volatile &' requires an lvalue" }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment