Skip to content

placementNew/placementDelete: simplify with if constexpr and trivially_copyable#5522

Closed
WeiqunZhang wants to merge 1 commit into
AMReX-Codes:developmentfrom
WeiqunZhang:placement
Closed

placementNew/placementDelete: simplify with if constexpr and trivially_copyable#5522
WeiqunZhang wants to merge 1 commit into
AMReX-Codes:developmentfrom
WeiqunZhang:placement

Conversation

@WeiqunZhang

@WeiqunZhang WeiqunZhang commented Jun 27, 2026

Copy link
Copy Markdown
Member

Replace the three requires-overloads of placementNew with a single function using if constexpr. Use std::is_trivially_copyable instead of std::is_trivially_default_constructible — trivially copyable types (including arithmetic and POD types) begin their lifetime implicitly once storage is allocated and need no placement-new. Add matching Doxygen comments for both functions.

Breaking change: BaseFab no longer default-constructs trivially copyable element types. Code that relied on BaseFab allocation/resize to initialize values, including BaseFab<GpuComplex> zero-initialization, must explicitly fill or write the data before reading it. This is consistent with the existing behavior for arithmetic types, which are not initialized on allocation; in that sense, the new behavior is arguably the less surprising one for BaseFab storage.

@WeiqunZhang WeiqunZhang requested a review from atmyers June 27, 2026 02:10
…y_copyable

Replace the three requires-overloads of placementNew with a single function
using if constexpr.  Use std::is_trivially_copyable instead of
std::is_trivially_default_constructible — trivially copyable types
(including arithmetic and POD types) begin their lifetime implicitly once
storage is allocated and need no placement-new.  Add matching Doxygen
comments for both functions.
@WeiqunZhang

Copy link
Copy Markdown
Member Author

Oh, there is EBCellFlagFab that depends on the default ctor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant