@@ -7681,17 +7681,6 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
&& !is_std_construct_at (ctx->call)
&& !is_std_allocator_allocate (ctx->call))
{
- /* P2738 (C++26): a conversion from a prvalue P of type "pointer to
- cv void" to a pointer-to-object type T unless P points to an
- object whose type is similar to T. */
- if (cxx_dialect > cxx23)
- if (tree ob
- = cxx_fold_indirect_ref (ctx, loc, TREE_TYPE (type), op))
- {
- r = build1 (ADDR_EXPR, type, ob);
- break;
- }
-
/* Likewise, don't error when casting from void* when OP is
&heap uninit and similar. */
tree sop = tree_strip_nop_conversions (op);
@@ -7699,6 +7688,16 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
&& VAR_P (TREE_OPERAND (sop, 0))
&& DECL_ARTIFICIAL (TREE_OPERAND (sop, 0)))
/* OK */;
+ /* P2738 (C++26): a conversion from a prvalue P of type "pointer to
+ cv void" to a pointer-to-object type T unless P points to an
+ object whose type is similar to T. */
+ else if (cxx_dialect > cxx23
+ && (sop = cxx_fold_indirect_ref (ctx, loc,
+ TREE_TYPE (type), sop)))
+ {
+ r = build1 (ADDR_EXPR, type, sop);
+ break;
+ }
else
{
if (!ctx->quiet)
@@ -6731,6 +6731,8 @@ get_cxx_dialect_name (enum cxx_dialect dialect)
return "C++20";
case cxx23:
return "C++23";
+ case cxx26:
+ return "C++26";
}
}
@@ -6,11 +6,11 @@ static int i;
constexpr void *vp0 = nullptr;
constexpr void *vpi = &i;
constexpr int *p1 = (int *) vp0; // { dg-error "cast from .void\\*. is not allowed" }
-constexpr int *p2 = (int *) vpi; // { dg-error "cast from .void\\*. is not allowed" }
+constexpr int *p2 = (int *) vpi; // { dg-error "cast from .void\\*. is not allowed" "" { target c++23_down } }
constexpr int *p3 = static_cast<int *>(vp0); // { dg-error "cast from .void\\*. is not allowed" }
-constexpr int *p4 = static_cast<int *>(vpi); // { dg-error "cast from .void\\*. is not allowed" }
+constexpr int *p4 = static_cast<int *>(vpi); // { dg-error "cast from .void\\*. is not allowed" "" { target c++23_down } }
constexpr void *p5 = vp0;
constexpr void *p6 = vpi;
constexpr int *pi = &i;
-constexpr bool b = ((int *)(void *) pi == pi); // { dg-error "cast from .void\\*. is not allowed" }
+constexpr bool b = ((int *)(void *) pi == pi); // { dg-error "cast from .void\\*. is not allowed" "" { target c++23_down } }
@@ -37,5 +37,5 @@ int main()
}
/* One invocation is A::foo () other is B::foo () even though the type is destroyed and rebuilt in test() */
-/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*A::foo" 2 "inline" } } */
+/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*A::foo" 2 "inline" { target { ! implicit_constexpr } } } }*/
/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*B::foo" 1 "inline" } } */