Commit ed3ea9f2 by Jakub Jelinek Committed by Jakub Jelinek

re PR c++/89599 (C-style function-pointer-to-void* cast is handled inconsistently)

	PR c++/89599
	* constexpr.c (potential_constant_expression_1): Reject
	REINTERPRET_CAST_P NOP_EXPRs.

	* g++.dg/ubsan/vptr-4.C: Adjust expected diagnostics.
	* g++.dg/parse/array-size2.C: Likewise.
	* g++.dg/cpp0x/constexpr-89599.C: New test.

From-SVN: r269482
parent 560a46a5
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.
......
......@@ -5961,6 +5961,13 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
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.
......
// 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" }
......@@ -15,6 +15,8 @@ void
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);
}
......@@ -19,7 +19,7 @@ struct T : S {
};
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 {
......@@ -39,17 +39,16 @@ struct W : V<U> {
};
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> ();
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