+2017-11-06 Jason Merrill <jason@redhat.com>
+
+ P0704R1 - fixing const-qualified pointers to members
+ * typeck2.c (build_m_component_ref): Also accept in lower stds with
+ a pedwarn.
+
2017-11-06 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/65579
ptrmem_type);
return error_mark_node;
}
- else if (!lval
- && !FUNCTION_RVALUE_QUALIFIED (type)
- && (cxx_dialect < cxx2a
- || ((type_memfn_quals (type)
- & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE))
- != TYPE_QUAL_CONST)))
+ else if (!lval && !FUNCTION_RVALUE_QUALIFIED (type))
{
- if (complain & tf_error)
- error ("pointer-to-member-function type %qT requires an lvalue",
- ptrmem_type);
- return error_mark_node;
+ if ((type_memfn_quals (type)
+ & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE))
+ != TYPE_QUAL_CONST)
+ {
+ if (complain & tf_error)
+ error ("pointer-to-member-function type %qT requires "
+ "an lvalue", ptrmem_type);
+ return error_mark_node;
+ }
+ else if (cxx_dialect < cxx2a)
+ {
+ if (complain & tf_warning_or_error)
+ pedwarn (input_location, OPT_Wpedantic,
+ "pointer-to-member-function type %qT requires "
+ "an lvalue before C++2a", ptrmem_type);
+ else
+ return error_mark_node;
+ }
}
}
return build2 (OFFSET_REF, type, datum, component);
--- /dev/null
+// P0704R1
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+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)();
+ (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" }
+}