Commit 5e1b4e60 by Patrick Palka

c++: Fix missing SFINAE when binding a bit-field to a reference (PR 93729)

We are unconditionally emitting an error here, without first checking complain.

gcc/cp/ChangeLog:

	PR c++/93729
	* call.c (convert_like_real): Check complain before emitting an error
	about binding a bit-field to a reference.

gcc/testsuite/ChangeLog:

	PR c++/93729
	* g++.dg/concepts/pr93729.C: New test.
parent ff0a6284
2020-03-08 Patrick Palka <ppalka@redhat.com> 2020-03-08 Patrick Palka <ppalka@redhat.com>
PR c++/93729
* call.c (convert_like_real): Check complain before emitting an error
about binding a bit-field to a reference.
* cxx-pretty-print.c (cxx_pretty_printer::simple_type_specifier) * cxx-pretty-print.c (cxx_pretty_printer::simple_type_specifier)
[TYPENAME_TYPE]: Print the TYPENAME_TYPE_FULLNAME instead of the [TYPENAME_TYPE]: Print the TYPENAME_TYPE_FULLNAME instead of the
TYPE_NAME. TYPE_NAME.
......
...@@ -7730,15 +7730,18 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -7730,15 +7730,18 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
{ {
/* If the reference is volatile or non-const, we /* If the reference is volatile or non-const, we
cannot create a temporary. */ cannot create a temporary. */
if (lvalue & clk_bitfield) if (complain & tf_error)
error_at (loc, "cannot bind bit-field %qE to %qT", {
expr, ref_type); if (lvalue & clk_bitfield)
else if (lvalue & clk_packed) error_at (loc, "cannot bind bit-field %qE to %qT",
error_at (loc, "cannot bind packed field %qE to %qT", expr, ref_type);
expr, ref_type); else if (lvalue & clk_packed)
else error_at (loc, "cannot bind packed field %qE to %qT",
error_at (loc, "cannot bind rvalue %qE to %qT", expr, ref_type);
expr, ref_type); else
error_at (loc, "cannot bind rvalue %qE to %qT",
expr, ref_type);
}
return error_mark_node; return error_mark_node;
} }
/* If the source is a packed field, and we must use a copy /* If the source is a packed field, and we must use a copy
......
2020-03-08 Patrick Palka <ppalka@redhat.com> 2020-03-08 Patrick Palka <ppalka@redhat.com>
PR c++/93729
* g++.dg/concepts/pr93729.C: New test.
* g++.dg/concepts/diagnostic4.C: New test. * g++.dg/concepts/diagnostic4.C: New test.
2020-03-08 H.J. Lu <hongjiu.lu@intel.com> 2020-03-08 H.J. Lu <hongjiu.lu@intel.com>
......
// { dg-do compile { target c++2a } }
// PR c++/93729
struct B
{
int a:4;
int b:4;
};
template<typename T>
concept c1
= requires(T x, void(f)(int &)) { f(x.a); }; // { dg-bogus "cannot bind" }
static_assert(!c1<B>);
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