]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/91962 - ICE with reference binding and qualification conversion.
authorMarek Polacek <polacek@redhat.com>
Mon, 18 Nov 2019 16:39:24 +0000 (16:39 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Mon, 18 Nov 2019 16:39:24 +0000 (16:39 +0000)
When fixing c++/91889 (r276251) I was assuming that we couldn't have a ck_qual
under a ck_ref_bind, and I was introducing it in the patch and so this
+   if (next_conversion (convs)->kind == ck_qual)
+     {
+       gcc_assert (same_type_p (TREE_TYPE (expr),
+                    next_conversion (convs)->type));
+       /* Strip the cast created by the ck_qual; cp_build_addr_expr
+          below expects an lvalue.  */
+       STRIP_NOPS (expr);
+     }
in convert_like_real was supposed to handle it.  But that assumption was wrong
as this test shows; here we have "(int *)f" where f is of type long int, and
we're converting it to "const int *const &", so we have both ck_ref_bind and
ck_qual.  That means that the new STRIP_NOPS strips an expression it shouldn't
have, and that then breaks when creating a TARGET_EXPR.  So we want to limit
the stripping to the new case only.  This I do by checking need_temporary_p,
which will be 0 in the new case.  Yes, we can set need_temporary_p when
binding a reference directly, but then we won't have a qualification
conversion.  It is possible to have a bit-field, convert it to a pointer,
and then convert that pointer to a more-qualified pointer, but in that case
we're not dealing with an lvalue, so gl_kind is 0, so we won't enter this
block in reference_binding:
 1747   if ((related_p || compatible_p) && gl_kind)

* call.c (convert_like_real) <case ck_ref_bind>: Check need_temporary_p.

* g++.dg/cpp0x/ref-bind7.C: New test.

From-SVN: r278416

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/ref-bind7.C [new file with mode: 0644]

index 4730d792c68edd48e82510e8699aad79dd390ec0..616a04bdd1d356c576bcaea1b38045e4388c06f4 100644 (file)
@@ -1,3 +1,8 @@
+2019-11-18  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/91962 - ICE with reference binding and qualification conversion.
+       * call.c (convert_like_real) <case ck_ref_bind>: Check need_temporary_p.
+
 2019-11-17  Jakub Jelinek  <jakub@redhat.com>
 
        * method.c (lookup_comparison_result): Use %qD instead of %<%T::%D%>
index e9ab30d9e13ed941cf6632634f32d3a3f8339760..13639a1c9010b542eb0345393fafdff14bdae20c 100644 (file)
@@ -7598,7 +7598,8 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
        /* direct_reference_binding might have inserted a ck_qual under
           this ck_ref_bind for the benefit of conversion sequence ranking.
           Ignore the conversion; we'll create our own below.  */
-       if (next_conversion (convs)->kind == ck_qual)
+       if (next_conversion (convs)->kind == ck_qual
+           && !convs->need_temporary_p)
          {
            gcc_assert (same_type_p (TREE_TYPE (expr),
                                     next_conversion (convs)->type));
index c7e4500c497624dbbab57c5a8d63421ccc416f95..d8bd2fa3382597b7d8947a62fa46e84a8d6696c2 100644 (file)
@@ -1,3 +1,8 @@
+2019-11-18  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/91962 - ICE with reference binding and qualification conversion.
+       * g++.dg/cpp0x/ref-bind7.C: New test.
+
 2019-11-18  Martin Jambor  <mjambor@suse.cz>
 
        PR ipa/92528
diff --git a/gcc/testsuite/g++.dg/cpp0x/ref-bind7.C b/gcc/testsuite/g++.dg/cpp0x/ref-bind7.C
new file mode 100644 (file)
index 0000000..e3675bc
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/91962 - ICE with reference binding and qualification conversion.
+// { dg-do compile { target c++11 } }
+
+template <typename a> class b {
+public:
+  void c(const a &);
+};
+class B {
+  void d();
+  b<const int *> e;
+};
+long f;
+void B::d() { e.c((const int *)f); }