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

Fix unique_ptr<T, Del> constructor of UniquePtrWithLambda #1552

Merged
merged 6 commits into from
Nov 7, 2023

Conversation

franzpoeschel
Copy link
Contributor

I forgot adding tests for that constructor and it turns out it is broken. It's the most generic conversion constructor that the class has (there is a specialization for std::unique_ptr<T>), so this is not used very often. There are two problems:

  1. The implementation calls get_deleter() twice. This PR removes the second invocation.
  2. std::function needs a copyable lambda, but Del might be non-copyable. Add a custom path for that case.

This PR adds two tests for each case. Without this PRs, the compile time errors are as follows:

1:

In file included from /.../openPMD-api/include/openPMD/auxiliary/TypeTraits.hpp:24,                                                
                 from /.../openPMD-api/include/openPMD/Datatype.hpp:23,                                                            
                 from /.../openPMD-api/test/SerialIOTest.cpp:2:                                                                    
/.../openPMD-api/include/openPMD/auxiliary/UniquePtr.hpp: In instantiation of 'openPMD::UniquePtrWithLambda<T>::UniquePtrWithLambda(std::unique_ptr<T, Del>) [with Del = detail::CopyableDeleter<int>; T = int]':
/.../openPMD-api/test/SerialIOTest.cpp:705:71:   required from here
/.../openPMD-api/include/openPMD/auxiliary/UniquePtr.hpp:151:27: error: 'const struct detail::CopyableDeleter<int>' has no member named 'get_deleter'
  151 |                   deleter.get_deleter()(del_ptr);

2:

In file included from /nix/store/b7hvml0m3qmqraz1022fwvyyg6fc1vdy-gcc-12.2.0/include/c++/12.2.0/functional:59,
                 from /.../openPMD-api/include/openPMD/auxiliary/UniquePtr.hpp:3,
                 from /.../openPMD-api/include/openPMD/auxiliary/TypeTraits.hpp:24,
                 from /.../openPMD-api/include/openPMD/Datatype.hpp:23,
                 from /.../openPMD-api/test/SerialIOTest.cpp:2:
/nix/store/b7hvml0m3qmqraz1022fwvyyg6fc1vdy-gcc-12.2.0/include/c++/12.2.0/bits/std_function.h: In instantiation of 'std::function<_Res(_ArgTypes ...)>::function(_Functor&&) [with _Functor = openPMD::UniquePtrWithLambda<int>::UniquePtrWithLambda<detail::NonCopyableDeleter<int> >(std::unique_ptr<int, detail::NonCopyableDeleter<int> >)::<lambda(openPMD::UniquePtrWithLambda<int>::T_decayed*)>; _Constraints = void; _Res = void; _ArgTypes = {int*}]':
/.../openPMD-api/include/openPMD/auxiliary/UniquePtr.hpp:143:17:   required from 'openPMD::UniquePtrWithLambda<T>::UniquePtrWithLambda(std::unique_ptr<T, Del>) [with Del = detail::NonCopyableDeleter<int>; T = int]'
/.../openPMD-api/test/SerialIOTest.cpp:728:74:   required from here
/nix/store/b7hvml0m3qmqraz1022fwvyyg6fc1vdy-gcc-12.2.0/include/c++/12.2.0/bits/std_function.h:439:69: error: static assertion failed: std::function target must be copy-constructible
  439 |           static_assert(is_copy_constructible<__decay_t<_Functor>>::value,

@franzpoeschel franzpoeschel added this to the 0.15.3 milestone Nov 6, 2023
@franzpoeschel
Copy link
Contributor Author

clang-format decided to make no captives today 68918b2

Copy link
Member

@ax3l ax3l left a comment

Choose a reason for hiding this comment

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

That looks wild. Ok.

@ax3l ax3l merged commit 442481a into openPMD:dev Nov 7, 2023
28 checks passed
@ax3l ax3l self-assigned this Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants