Skip to content
Snippets Groups Projects
Commit 895dd027 authored by Marek Polacek's avatar Marek Polacek
Browse files

c++: fixes for derived-to-base reference binding [PR107085]

This PR reports that

  struct Base {};
  struct Derived : Base {};
  static_assert(__reference_constructs_from_temporary(Base const&, Derived));

doesn't pass, which it should: it's just like

  const Base& b(Derived{});

where we bind 'b' to the Base subobject of a temporary object of type
Derived.  The ck_base conversion didn't have ->need_temporary_p set because
we didn't need to create a temporary object just for the base, but the whole
object is a temporary so we're still binding to a temporary.  Since the
Base subobject is an xvalue, a new function is introduced.

	PR c++/107085

gcc/cp/ChangeLog:

	* call.cc (conv_binds_ref_to_temporary): New.
	(ref_conv_binds_directly): Rename to...
	(ref_conv_binds_to_temporary): ...this.  Use
	conv_binds_ref_to_temporary.
	* cp-tree.h (ref_conv_binds_directly): Rename to...
	(ref_conv_binds_to_temporary): ...this.
	* method.cc (ref_xes_from_temporary): Use ref_conv_binds_to_temporary.
	* parser.cc (warn_for_range_copy): Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/ext/reference_constructs_from_temporary1.C: Adjust expected
	result.
	* g++.dg/ext/reference_converts_from_temporary1.C: Likewise.
	* g++.dg/cpp0x/elision4.C: New test.
parent f30e9fd3
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment