Skip to content
Snippets Groups Projects
Commit afa3a4a5 authored by Jakub Jelinek's avatar Jakub Jelinek Committed by Jakub Jelinek
Browse files

c++, libstdc++: Implement C++26 P2747R2 - constexpr placement new [PR115744]

With the PR115754 fix in, constexpr placement new mostly just works,
so this patch just adds constexpr keyword to the placement new operators
in <new>, adds FTMs and testsuite coverage.

There is one accepts-invalid though, the
new (p + 1) int[]{2, 3};      // error (in this paper)
case from the paper.  Can we handle that incrementally?
The problem with that is I think calling operator new now that it is
constexpr should be fine even in that case in constant expressions, so
int *p = std::allocator<int>{}.allocate(3);
int *q = operator new[] (sizeof (int) * 2, p + 1);
should be ok, so it can't be easily the placement new operator call
itself on whose constexpr evaluation we try something special, it should
be on the new expression, but constexpr.cc actually sees only
<<< Unknown tree: expr_stmt
  (void) (TARGET_EXPR <D.2640, (void *) TARGET_EXPR <D.2641, VIEW_CONVERT_EXPR<int *>(b) + 4>>, TARGET_EXPR <D.2642, operator new [] (8, NON_LVALUE_EXPR <D.2640>)>,   int * D.2643;
  <<< Unknown tree: expr_stmt
    (void) (D.2643 = (int *) D.2642) >>>;
and that is just fine by the preexisting constexpr evaluation rules.

Should build_new_1 emit some extra cast for the array cases with placement
new in maybe_constexpr_fn (current_function_decl) that the existing P2738
code would catch?

2024-08-08  Jakub Jelinek  <jakub@redhat.com>

	PR c++/115744
gcc/c-family/
	* c-cppbuiltin.cc (c_cpp_builtins): Change __cpp_constexpr
	from 202306L to 202406L for C++26.
gcc/testsuite/
	* g++.dg/cpp2a/construct_at.h (operator new, operator new[]):
	Use constexpr instead of inline if __cpp_constexpr >= 202406L.
	* g++.dg/cpp26/constexpr-new1.C: New test.
	* g++.dg/cpp26/constexpr-new2.C: New test.
	* g++.dg/cpp26/constexpr-new3.C: New test.
	* g++.dg/cpp26/feat-cxx26.C (__cpp_constexpr): Adjust expected
	value.
libstdc++-v3/
	* libsupc++/new (__glibcxx_want_constexpr_new): Define before
	including bits/version.h.
	(_GLIBCXX_PLACEMENT_CONSTEXPR): Define.
	(operator new, operator new[]): Use it for placement new instead
	of inline.
	* include/bits/version.def (constexpr_new): New FTM.
	* include/bits/version.h: Regenerate.
parent e3a6dec3
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment