From a55f758221cfd574cc341f969c27f8ecdac087a4 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Mon, 25 Mar 2019 16:10:06 +0000 Subject: [PATCH] PR c++/89705 - ICE with reference binding with conversion function. * call.c (reference_binding): If the result of the conversion function is a prvalue of non-class type, use the cv-unqualified type. * g++.dg/cpp0x/rv-conv2.C: New test. From-SVN: r269918 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/call.c | 3 +++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/rv-conv2.C | 18 ++++++++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/rv-conv2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7589b30..b2b7b41 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-03-25 Marek Polacek + + PR c++/89705 - ICE with reference binding with conversion function. + * call.c (reference_binding): If the result of the conversion function + is a prvalue of non-class type, use the cv-unqualified type. + 2019-03-25 Nathan Sidwell * lambda.c (maybe_add_lambda_conv_op): Don't add to comdat group. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index a4adab2..9efca73 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -1853,6 +1853,9 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags, && DECL_CONV_FN_P (t->cand->fn)) { tree ftype = TREE_TYPE (TREE_TYPE (t->cand->fn)); + /* A prvalue of non-class type is cv-unqualified. */ + if (!TYPE_REF_P (ftype) && !CLASS_TYPE_P (ftype)) + ftype = cv_unqualified (ftype); int sflags = (flags|LOOKUP_NO_CONVERSION)&~LOOKUP_NO_TEMP_BIND; conversion *new_second = reference_binding (rto, ftype, NULL_TREE, c_cast_p, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7e1978b..01364a9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-03-25 Marek Polacek + + PR c++/89705 - ICE with reference binding with conversion function. + * g++.dg/cpp0x/rv-conv2.C: New test. + 2019-03-25 Richard Biener PR tree-optimization/89789 diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-conv2.C b/gcc/testsuite/g++.dg/cpp0x/rv-conv2.C new file mode 100644 index 0000000..9b9b154 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/rv-conv2.C @@ -0,0 +1,18 @@ +// PR c++/89705 +// { dg-do compile { target c++11 } } + +struct W { operator const volatile int(); }; +const int& rci = W(); + +struct X { operator const int(); }; +int&& rri = X(); + +struct Y { operator volatile int(); }; +int&& rri2 = Y(); + +struct Z { operator const volatile int(); }; +volatile int&& rri3 = Z(); + +enum E { A }; +struct S { operator const E(); }; +E&& rre = S(); -- 2.7.4