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.
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%>",
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)
--- /dev/null
+// PR c++/89331
+
+class A {
+public:
+ char a;
+};
+
+class B : public A {
+public:
+ static const unsigned b = __builtin_offsetof(B, a); // { dg-error "incomplete" }
+};
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 }
+};