+2018-08-08 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/86738
+ * constexpr.c (cxx_eval_binary_expression): For arithmetics involving
+ NULL pointer set *non_constant_p to true.
+ (cxx_eval_component_reference): For dereferencing of a NULL pointer,
+ set *non_constant_p to true and return t.
+
2018-08-07 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/59480, DR 136
{
if (!ctx->quiet)
error ("arithmetic involving a null pointer in %qE", lhs);
+ *non_constant_p = true;
return t;
}
else if (code == POINTER_PLUS_EXPR)
lval,
non_constant_p, overflow_p);
if (INDIRECT_REF_P (whole)
- && integer_zerop (TREE_OPERAND (whole, 0))
- && !ctx->quiet)
- error ("dereferencing a null pointer in %qE", orig_whole);
+ && integer_zerop (TREE_OPERAND (whole, 0)))
+ {
+ if (!ctx->quiet)
+ error ("dereferencing a null pointer in %qE", orig_whole);
+ *non_constant_p = true;
+ return t;
+ }
if (TREE_CODE (whole) == PTRMEM_CST)
whole = cplus_expand_constant (whole);
--- /dev/null
+// PR c++/86738
+// { dg-do compile }
+
+struct S { int s; };
+unsigned char a[20];
+unsigned char *p = &a[(__UINTPTR_TYPE__) &((S *) 0)->s];
+
+void
+foo ()
+{
+ __builtin_memcpy (&a[15], &a[(__UINTPTR_TYPE__) &((S *) 0)->s], 2);
+}