Commit b8836dbe by Jason Merrill Committed by Jason Merrill

PR c++/89331 - ICE with offsetof in incomplete class.

We were aborting when build_base_path returned an error because of the
derived class not being complete yet, which wasn't considered by the assert.
Fixed by checking for complete type first.  The semantics.c change avoids
a duplicate error message.

	* semantics.c (finish_offsetof): Handle error_mark_node.
	* typeck.c (build_class_member_access_expr): Call
	complete_type_or_maybe_complain before converting to base.

From-SVN: r270135
parent bc53dee0
2019-04-03 Jason Merrill <jason@redhat.com>
PR c++/89331 - ICE with offsetof in incomplete class.
* semantics.c (finish_offsetof): Handle error_mark_node.
* typeck.c (build_class_member_access_expr): Call
complete_type_or_maybe_complain before converting to base.
PR c++/89917 - ICE with lambda in variadic mem-init.
* pt.c (make_pack_expansion): Change type_pack_expansion_p to false.
......
......@@ -4144,6 +4144,9 @@ finish_offsetof (tree object_ptr, tree expr, location_t loc)
return expr;
}
if (expr == error_mark_node)
return error_mark_node;
if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
{
error ("cannot apply %<offsetof%> to destructor %<~%T%>",
......
......@@ -2474,6 +2474,14 @@ build_class_member_access_expr (cp_expr object, tree member,
tree binfo;
base_kind kind;
/* We didn't complain above about a currently open class, but now we
must: we don't know how to refer to a base member before layout is
complete. But still don't complain in a template. */
if (!dependent_type_p (object_type)
&& !complete_type_or_maybe_complain (object_type, object,
complain))
return error_mark_node;
binfo = lookup_base (access_path ? access_path : object_type,
member_scope, ba_unique, &kind, complain);
if (binfo == error_mark_node)
......
// PR c++/89331
class A {
public:
char a;
};
class B : public A {
public:
static const unsigned b = __builtin_offsetof(B, a); // { dg-error "incomplete" }
};
......@@ -9,4 +9,4 @@ struct B: virtual A { };
int a[] = {
!&((B*)0)->i, // { dg-error "invalid access to non-static data member" }
__builtin_offsetof (B, i) // { dg-error "invalid access to non-static" }
}; // { dg-message "offsetof within non-standard-layout type" "" { target *-*-* } .-1 }
};
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