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.
Showing
- gcc/c-family/c-cppbuiltin.cc 1 addition, 1 deletiongcc/c-family/c-cppbuiltin.cc
- gcc/testsuite/g++.dg/cpp26/constexpr-new1.C 66 additions, 0 deletionsgcc/testsuite/g++.dg/cpp26/constexpr-new1.C
- gcc/testsuite/g++.dg/cpp26/constexpr-new2.C 73 additions, 0 deletionsgcc/testsuite/g++.dg/cpp26/constexpr-new2.C
- gcc/testsuite/g++.dg/cpp26/constexpr-new3.C 47 additions, 0 deletionsgcc/testsuite/g++.dg/cpp26/constexpr-new3.C
- gcc/testsuite/g++.dg/cpp26/feat-cxx26.C 2 additions, 2 deletionsgcc/testsuite/g++.dg/cpp26/feat-cxx26.C
- gcc/testsuite/g++.dg/cpp2a/construct_at.h 14 additions, 1 deletiongcc/testsuite/g++.dg/cpp2a/construct_at.h
- libstdc++-v3/include/bits/version.def 9 additions, 0 deletionslibstdc++-v3/include/bits/version.def
- libstdc++-v3/include/bits/version.h 10 additions, 0 deletionslibstdc++-v3/include/bits/version.h
- libstdc++-v3/libsupc++/new 13 additions, 2 deletionslibstdc++-v3/libsupc++/new
Loading
Please register or sign in to comment