1

Originated from this Programmers topic. Does the C++14 standard ever allow the usage std::unique_ptr<void>? GCC 5.2 (C++14) produced the following error message with std::unique_ptr<void>:

In file included from /usr/local/gcc-5.2.0/include/c++/5.2.0/memory:81:0,
                 from prog.cc:1:
/usr/local/gcc-5.2.0/include/c++/5.2.0/bits/unique_ptr.h: In instantiation of 'void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = void]':
/usr/local/gcc-5.2.0/include/c++/5.2.0/bits/unique_ptr.h:236:17:   required from 'std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = void; _Dp = std::default_delete<void>]'
prog.cc:4:25:   required from here
/usr/local/gcc-5.2.0/include/c++/5.2.0/bits/unique_ptr.h:72:2: error: static assertion failed: can't delete pointer to incomplete type
  static_assert(!is_void<_Tp>::value,
  ^

Obviously, this particular standard library implementation has specifically forbidden such usage. But what does the standard say about this? Language-lawyers would be apt here.

Community
  • 1
  • 1
Lingxi
  • 14,579
  • 2
  • 37
  • 93

0 Answers0