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

Adding namespace to avoid conflict with C++20 construct_at #103

Merged
merged 3 commits into from
Jan 31, 2024
Merged

Adding namespace to avoid conflict with C++20 construct_at #103

merged 3 commits into from
Jan 31, 2024

Conversation

g-217
Copy link
Contributor

@g-217 g-217 commented Oct 17, 2023

With C++20 I was getting compilation errors because of ambiguity in selecting construct_at, construct_at is defined in both std & adobe namespace.

Copy link
Member

@sean-parent sean-parent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One change requested - the remaining changes look good.

@@ -364,9 +364,9 @@ constexpr T* construct_at(T* p, Args&&... args) {
#else

template <class T, class... Args>
constexpr T* construct_at(T* p, Args&&... args) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't even know what I was thinking with this code -
Having the conditional in the header is asking for ODR violations. I would suggest starting at line [356-370] be replaced with:

template <class T, class... Args>
T* construct_at(T* p, Args&&... args) {
    return ::new (static_cast<void*>(p)) T(std::forward<Args>(args)...);
}

From cppreference. The constexpr with the cast isn't doing anything, and I'm surprised it doesn't generate a warning. Clearly, the C++20 implementation never compiled; your suggestion loses the constexpr-ness of the standard call. Let's keep it simple and when we require C++20 we can deprecate this instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced the code between lines [356-370] with suggested implementation.

@g-217 g-217 requested a review from sean-parent January 29, 2024 12:16
@sean-parent
Copy link
Member

LGTM

@sean-parent sean-parent merged commit 5d33fb9 into stlab:main Jan 31, 2024
5 checks passed
@g-217 g-217 deleted the gjha/construct_at_fix branch February 2, 2024 05:54
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