Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further trivially-relocatable support #2

Merged

Conversation

Quuxplusone
Copy link
Contributor

This addresses my late-breaking "oops" comment from #1.
I strongly recommend testing "error.cpp" in all modes with GCC and/or your compiler of choice, before merging this one. :)

For example, if the P1144-enabled library (or even Clang trunk with
libc++'s `_LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI` defined) reports
that `unique_ptr` is trivially relocatable, then we should use that.

A type which is trivially move-constructible and trivially destructible
but NOT trivially move-assignable, is not considered trivially relocatable
by P1144. `stdx::error` could actually take its trivial codepaths for
such a type, but if anyone actually used such a type with `stdx::error`
today, then when they upgraded to a P1144-enabled compiler, they'd start
getting errors because their type was no longer considered trivially
relocatable. It seems more futureproof to be conservative in the
"zero compiler/library support" codepath, and accept only types that
are 100% trivially copyable. (Move-only types can indeed be trivially
copyable, and I'm not aware of any type that is known to the compiler
to be trivially constructible and destructible without also being
trivially assignable, so I claim this is fine.)

"test.cpp" now compiles with Clang trunk and also my Clang P1144 fork,
in C++14, 17, 20, and 23.

@Quuxplusone
Copy link
Contributor Author

Quuxplusone commented Nov 9, 2023

Darn it, MSVC is unhappy with #elif __has_builtin(__is_trivially_relocatable)...
...okay, I copied libc++'s approach of wrapping that test inside a test of #ifdef __has_builtin. This involved some duplication but isn't too bad.

For example, if the P1144-enabled library (or even Clang trunk with
libc++'s `_LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI` defined) reports
that `unique_ptr` is trivially relocatable, then we should use that.

A type which is trivially move-constructible and trivially destructible
but NOT trivially move-assignable, is not considered trivially relocatable
by P1144. `stdx::error` could actually take its trivial codepaths for
such a type, but if anyone actually used such a type with `stdx::error`
today, then when they upgraded to a P1144-enabled compiler, they'd start
getting errors because their type was no longer considered trivially
relocatable. It seems more futureproof to be conservative in the
"zero compiler/library support" codepath, and accept only types that
are 100% trivially copyable. (Move-only types can indeed be trivially
copyable, and I'm not aware of any type that is known to the compiler
to be trivially constructible and destructible without also being
trivially assignable, so I claim this is fine.)

"test.cpp" now compiles with Clang trunk and also my Clang P1144 fork,
in C++14, 17, 20, and 23.
@charles-salvia
Copy link
Owner

Looks good to me.

@charles-salvia charles-salvia merged commit 25a2263 into charles-salvia:master Nov 11, 2023
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.

2 participants