标准是否允许`std :: unique_ptr <void>`?

时间:2016-01-30 05:43:24

标签: c++ language-lawyer c++14 unique-ptr c++-standard-library

源自this程序员主题。 C ++ 14标准是否允许使用std::unique_ptr<void>? GCC 5.2(C ++ 14)使用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,
  ^

显然,这种特殊的标准库实现已经明确禁止这种用法。但标准对此有何看法?语言律师会适合这里。

0 个答案:

没有答案