2018-04-09 Jason Merrill <jason@redhat.com>
+ PR c++/85277 - ICE with invalid offsetof.
+ * semantics.c (finish_offsetof): Avoid passing non-DECL to %qD.
+ Adjust -Winvalid-offsetof diagnostic to say conditionally supported.
+
PR c++/85264 - ICE with excess template-parameter-list.
* parser.c (cp_parser_check_template_parameters): Add template_id_p
parameter. Don't allow an extra template header if true.
|| TREE_CODE (TREE_TYPE (expr)) == METHOD_TYPE
|| TREE_TYPE (expr) == unknown_type_node)
{
- if (INDIRECT_REF_P (expr))
- error ("second operand of %<offsetof%> is neither a single "
- "identifier nor a sequence of member accesses and "
- "array references");
- else
+ while (TREE_CODE (expr) == COMPONENT_REF
+ || TREE_CODE (expr) == COMPOUND_EXPR)
+ expr = TREE_OPERAND (expr, 1);
+
+ if (DECL_P (expr))
{
- if (TREE_CODE (expr) == COMPONENT_REF
- || TREE_CODE (expr) == COMPOUND_EXPR)
- expr = TREE_OPERAND (expr, 1);
error ("cannot apply %<offsetof%> to member function %qD", expr);
+ inform (DECL_SOURCE_LOCATION (expr), "declared here");
}
+ else
+ error ("cannot apply %<offsetof%> to member function");
return error_mark_node;
}
if (TREE_CODE (expr) == CONST_DECL)
&& CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr)))
&& CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr)))
&& cp_unevaluated_operand == 0)
- pedwarn (loc, OPT_Winvalid_offsetof,
- "offsetof within non-standard-layout type %qT is undefined",
- TREE_TYPE (TREE_TYPE (object_ptr)));
+ warning_at (loc, OPT_Winvalid_offsetof, "offsetof within "
+ "non-standard-layout type %qT is conditionally-supported",
+ TREE_TYPE (TREE_TYPE (object_ptr)));
return fold_offsetof (expr);
}
// PR c++/51413
-// { dg-options "-w" }
+// PR c++/85277
+// { dg-options "-Wno-pointer-arith" }
struct A
{
static void foo();
};
-int i = __builtin_offsetof(A, foo[1]); // { dg-error "neither a single identifier nor a sequence of member accesses and array references" }
+int i = __builtin_offsetof(A, foo[1]); // { dg-error "offsetof" }
+int j = __builtin_offsetof(volatile A, foo[0]); // { dg-error "offsetof" }
int &i;
};
-int j = offsetof (A, i); // { dg-error "offsetof" }
+int j = offsetof (A, i); // { dg-message "offsetof" }
template <typename T>
struct S
{
T h;
T &i;
- static const int j = offsetof (S, i); // { dg-error "offsetof" }
+ static const int j = offsetof (S, i); // { dg-message "offsetof" }
};
int k = S<int>::j; // { dg-message "required from here" }
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-error "offsetof within non-standard-layout type" "" { target *-*-* } .-1 }
+}; // { dg-message "offsetof within non-standard-layout type" "" { target *-*-* } .-1 }