Issue 170123
Summary [libc++] std::function move constructor doesn't compile with `-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES`
Labels libc++
Assignees
Reporter msenica
    https://godbolt.org/z/cnonfeW8e

```cpp
#include <functional>

void test() {
    std::function<void(void)> f = [] { };
}
```
Compiling with `-std=c++14 -stdlib=libc++ -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES` fails:
```
In file included from <source>:1:
In file included from /cefs/ed/ed52bd7ae910fa279dd74bf8_clang-trunk-20251201/bin/../include/c++/v1/functional:553:
/cefs/ed/ed52bd7ae910fa279dd74bf8_clang-trunk-20251201/bin/../include/c++/v1/__functional/function.h:211:14: error: no matching 'operator new' function for non-allocating placement new _expression_; include <new>
  211 |       __f_ = ::new (std::addressof(__buf_)) _Fun(std::move(__f));
      | ^~
/cefs/ed/ed52bd7ae910fa279dd74bf8_clang-trunk-20251201/bin/../include/c++/v1/__functional/function.h:711:50: note: in instantiation of function template specialization 'std::__function::__value_func<void ()>::__value_func<(lambda at <source>:4:35), 0>' requested here
  711 | function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(std::move(__f)) {}
 |                                                  ^
<source>:4:35: note: in instantiation of function template specialization 'std::function<void ()>::function<(lambda at <source>:4:35), void>' requested here
    4 | std::function<void(void)> f = [] { };
      | ^
1 error generated.
Compiler returned: 1
```
Adding `#include <new>` as the error message suggests does of course make the compilation error go away. However, I don't think this is expected behavior - my understanding is that the `_LIBCPP_REMOVE_TRANSITIVE_INCLUDES` definition will only remove _unnecessary_ transitive includes.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to