2019-03-08 Jakub Jelinek <jakub@redhat.com>
+ PR c++/89599
+ * constexpr.c (potential_constant_expression_1): Reject
+ REINTERPRET_CAST_P NOP_EXPRs.
+
PR c++/89622
* call.c (joust): Call print_z_candidate only if pedwarn returned
true.
return true;
case NOP_EXPR:
+ if (REINTERPRET_CAST_P (t))
+ {
+ if (flags & tf_error)
+ error_at (loc, "a reinterpret_cast is not a constant expression");
+ return false;
+ }
+ /* FALLTHRU */
case CONVERT_EXPR:
case VIEW_CONVERT_EXPR:
/* -- a reinterpret_cast. FIXME not implemented, and this rule
2019-03-08 Jakub Jelinek <jakub@redhat.com>
+ PR c++/89599
+ * g++.dg/ubsan/vptr-4.C: Adjust expected diagnostics.
+ * g++.dg/parse/array-size2.C: Likewise.
+ * g++.dg/cpp0x/constexpr-89599.C: New test.
+
PR c++/89622
* g++.dg/warn/pr89622.C: New test.
--- /dev/null
+// PR c++/89599
+// { dg-do compile { target c++11 } }
+
+void foo (int x) {}
+constexpr void *arr[2] = { (void*) &foo, (void *) foo };// { dg-error "a reinterpret_cast is not a constant expression" }
+constexpr void *ptr = (void *) &foo; // { dg-error "a reinterpret_cast is not a constant expression" }
foo (void)
{
char g[(char *) &((struct S *) 0)->b - (char *) 0]; // { dg-error "40:size of array .g. is not an integral constant-expression" }
+ // { dg-error "narrowing conversion" "" { target c++11 } .-1 }
+ // { dg-message "expression has a constant value but is not a C.. constant-expression" "" { target c++11 } .-2 }
char h[(__SIZE_TYPE__) &((struct S *) 8)->b]; // { dg-error "10:size of array .h. is not an integral constant-expression" }
bar (g, h);
}
};
constexpr T t;
-constexpr const T *p = t.foo (); // { dg-message "expansion of" }
+constexpr const T *p = t.foo (); // { dg-error "called in a constant expression" }
template <typename U>
struct V {
};
constexpr W<int> w;
-constexpr const W<int> *s = w.foo (); // { dg-error "is not a constant expression" }
-// { dg-message "expansion of" "" { target *-*-* } .-1 }
+constexpr const W<int> *s = w.foo (); // { dg-error "called in a constant expression" }
template <typename U>
int foo (void)
{
static constexpr T t;
- static constexpr const T *p = t.foo (); // { dg-message "expansion of" }
+ static constexpr const T *p = t.foo (); // { dg-error "called in a constant expression" }
static constexpr W<U> w;
- static constexpr const W<U> *s = w.foo (); // { dg-error "is not a constant expression" }
- return t.b + w.b; // { dg-message "expansion of" "" { target *-*-* } .-1 }
+ static constexpr const W<U> *s = w.foo (); // { dg-error "called in a constant expression" }
+ return t.b + w.b;
}
int x = foo <char> ();