Commit 17b20aa9 by Marek Polacek Committed by Marek Polacek

PR c++/87109 - wrong ctor with maybe-rvalue semantics.

	* call.c (build_user_type_conversion_1): Refine the maybe-rvalue
	check to only return if we're converting the return value to a base
	class.

	* g++.dg/cpp0x/ref-qual19.C: Adjust the expected results.
	* g++.dg/cpp0x/ref-qual20.C: New test.

From-SVN: r264452
parent 0b7fb27b
2018-09-20 Marek Polacek <polacek@redhat.com>
PR c++/87109 - wrong ctor with maybe-rvalue semantics.
* call.c (build_user_type_conversion_1): Refine the maybe-rvalue
check to only return if we're converting the return value to a base
class.
2018-09-20 Allan Sandfeld Jensen <allan.jensen@qt.io>
* g++spec.c (lang_specific_driver): Handle -r like -nostdlib.
......
......@@ -4034,10 +4034,12 @@ build_user_type_conversion_1 (tree totype, tree expr, int flags,
conv->bad_p = true;
/* We're performing the maybe-rvalue overload resolution and
a conversion function is in play. This isn't going to work
because we would not end up with a suitable constructor. */
a conversion function is in play. Reject converting the return
value of the conversion function to a base class. */
if ((flags & LOOKUP_PREFER_RVALUE) && !DECL_CONSTRUCTOR_P (cand->fn))
return NULL;
for (conversion *t = cand->second_conv; t; t = next_conversion (t))
if (t->kind == ck_base)
return NULL;
/* Remember that this was a list-initialization. */
if (flags & LOOKUP_NO_NARROWING)
......
2018-09-20 Marek Polacek <polacek@redhat.com>
PR c++/87109 - wrong ctor with maybe-rvalue semantics.
* g++.dg/cpp0x/ref-qual19.C: Adjust the expected results.
* g++.dg/cpp0x/ref-qual20.C: New test.
2018-09-20 Allan Sandfeld Jensen <allan.jensen@qt.io>
* g++.dg/ipa/pr64059.C: Removed now redundant -nostdlib.
......
......@@ -85,13 +85,13 @@ int
main ()
{
C c1 = f (A());
if (c1.i != 1)
if (c1.i != 2)
__builtin_abort ();
C c2 = f2 (A());
if (c2.i != 2)
__builtin_abort ();
C c3 = f3 ();
if (c3.i != 1)
if (c3.i != 2)
__builtin_abort ();
C c4 = f4 ();
if (c4.i != 2)
......@@ -100,13 +100,13 @@ main ()
if (c5.i != 2)
__builtin_abort ();
D c6 = f6 (B());
if (c6.i != 3)
if (c6.i != 4)
__builtin_abort ();
D c7 = f7 (B());
if (c7.i != 4)
__builtin_abort ();
D c8 = f8 ();
if (c8.i != 3)
if (c8.i != 4)
__builtin_abort ();
D c9 = f9 ();
if (c9.i != 4)
......
// PR c++/87109
// { dg-do run { target c++11 } }
#include <utility>
struct Y {
int y;
Y(int y_) : y(y_) { }
};
struct X : public Y {
int x;
X(int x_, int y_) : x(x_), Y(y_) { }
};
struct A {
operator X() & { return { 0, 2 }; }
operator X() && { return { 0, -1 }; }
};
Y
f (A a)
{
return a;
}
Y
f2 (A a)
{
return std::move (a);
}
Y
f3 ()
{
A a;
return a;
}
Y
f4 ()
{
A a;
return std::move (a);
}
Y
f5 ()
{
return A();
}
int
main ()
{
Y y1 = f (A());
if (y1.y != 2)
__builtin_abort ();
Y y2 = f2 (A());
if (y2.y != -1)
__builtin_abort ();
Y y3 = f3 ();
if (y3.y != 2)
__builtin_abort ();
Y y4 = f4 ();
if (y4.y != -1)
__builtin_abort ();
Y y5 = f5 ();
if (y5.y != -1)
__builtin_abort ();
}
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