]> https://gitweb.dealii.org/ - dealii.git/commit
Step-75: use well-formed deleter 13747/head
authorMatthias Maier <tamiko@43-1.org>
Tue, 17 May 2022 04:29:57 +0000 (23:29 -0500)
committerMatthias Maier <tamiko@43-1.org>
Tue, 17 May 2022 06:32:16 +0000 (01:32 -0500)
commit25a27f124a133d85b934f13faa1642e3c63dc9df
tree1e6bcda31356cd40af64190accbd7313ab5bb15a
parent3d869ba6cd1fd462624e09dc232e34ed17880701
Step-75: use well-formed deleter

LLVM/Clang's libc++ library version 13/14 got stricter by checking
requirements of the deleter, in particular, according to [1] a deleter
must pass the requirement `__shared_ptr_deleter_ctor_reqs` which is
defined as follows:
```
template <class _Dp, class _Pt, class = decltype(declval<_Dp>()(declval<_Pt>()))>
static true_type __well_formed_deleter_test(int);

template <class, class>
static false_type __well_formed_deleter_test(...);

template <class _Dp, class _Pt>
struct __well_formed_deleter : decltype(__well_formed_deleter_test<_Dp, _Pt>(0)) {};

template<class _Dp, class _Tp, class _Yp>
struct __shared_ptr_deleter_ctor_reqs
{
    static const bool value = __compatible_with<_Tp, _Yp>::value &&
                              is_move_constructible<_Dp>::value &&
                              __well_formed_deleter<_Dp, _Tp*>::value;
};
```
Unfortunately, our construct
```
coarse_grid_triangulations.emplace_back(
  const_cast<Triangulation<dim> *>(&(dof_handler.get_triangulation())),
  [](auto &) {});
```
does not pass this test. The issue is that the deleter takes a pointer,
not a reference which, so the lambda `[](auto &){}` does not pass above
`__shared_ptr_deleter_ctor_reqs`.

While at it, remove the const cast: `coarse_grid_triangulations` is
declared as a vector holding a `shared_ptr<const Triangulation<dim>>`,
thus we should simply take the address and not convert to a non-const
object.

[1] https://github.com/llvm/llvm-project/blob/main/libcxx/include/__memory/shared_ptr.h
examples/step-75/step-75.cc

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.