This started to ICE with my CWG 2352 fix.  In reference_binding, we now bind
directly when the types are similar, not just when they are the same.  But even
direct binding can involve a temporary, e.g. for a bit-field, or, as in this
test, for a packed field.

convert_like will actually create the temporary, but we were triggering the
assert checking that the types are the same.  Now they don't have to be, so
adjust the assert accordingly.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2019-09-24  Marek Polacek  <pola...@redhat.com>

        PR c++/91877 - ICE with converting member of packed struct.
        * call.c (convert_like_real): Use similar_type_p in an assert.

        * g++.dg/conversion/packed1.C: New test.

diff --git gcc/cp/call.c gcc/cp/call.c
index 77f10a9f5f1..45b984ecb11 100644
--- gcc/cp/call.c
+++ gcc/cp/call.c
@@ -7382,8 +7382,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, 
int argnum,
            tree type = TREE_TYPE (ref_type);
            cp_lvalue_kind lvalue = lvalue_kind (expr);
 
-           gcc_assert (same_type_ignoring_top_level_qualifiers_p
-                       (type, next_conversion (convs)->type));
+           gcc_assert (similar_type_p (type, next_conversion (convs)->type));
            if (!CP_TYPE_CONST_NON_VOLATILE_P (type)
                && !TYPE_REF_IS_RVALUE (ref_type))
              {
diff --git gcc/testsuite/g++.dg/conversion/packed1.C 
gcc/testsuite/g++.dg/conversion/packed1.C
new file mode 100644
index 00000000000..c4be930bc19
--- /dev/null
+++ gcc/testsuite/g++.dg/conversion/packed1.C
@@ -0,0 +1,12 @@
+// PR c++/91877 - ICE with converting member of packed struct.
+// { dg-do compile { target c++11 } }
+// { dg-options "-fpack-struct" }
+
+template <typename a> class b {
+public:
+  b(const a &);
+};
+struct {
+  int *c;
+} d;
+void e() { b<const int *>(d.c); }

Reply via email to