[cfe-dev] [clang-3.2] unique_ptr: compiler errors

Richard Smith richard at metafoo.co.uk
Mon Jun 4 17:19:40 PDT 2012


Hi,

On Sat, Jun 2, 2012 at 10:45 AM, Suman Kar <skarpio at gmail.com> wrote:
> Hello,
>
> The following:
>
> #include <memory>
> int main() {
>  using namespace std;
>  unique_ptr<int> up( new int( 30 ) );
> }
>
> generates:
>
> $ /d/llvm_workspace/build/Debug+Asserts/bin/clang++ -std=c++11 -Wall foo.cpp
>  -o foo
> In file included from vector.cpp:1:
> In file included from c:/MinGW/lib/gcc/mingw32/4.6.2/include/c++\memory:75:
> c:/MinGW/lib/gcc/mingw32/4.6.2/include/c++\ext/concurrence.h:228:2: error: no
>      matching function for call to '_S_destroy'
>        _S_destroy(&_M_mutex);
>        ^~~~~~~~~~
> c:/MinGW/lib/gcc/mingw32/4.6.2/include/c++\ext/concurrence.h:273:7: note:
>      candidate template ignored: substitution failure [with _Rm =
>      __gthread_recursive_mutex_t]: non-type template argument evaluates to 4,
>      which cannot be narrowed to type 'bool'
>      _S_destroy(_Rm* __mx)
>      ^
> c:/MinGW/lib/gcc/mingw32/4.6.2/include/c++\ext/concurrence.h:282:7: note:
>      candidate template ignored: substitution failure [with _Rm =
>      __gthread_recursive_mutex_t]: no member named 'actual' in
>      '__gthread_recursive_mutex_t'
>      _S_destroy(_Rm* __mx)
>      ^
> c:/MinGW/lib/gcc/mingw32/4.6.2/include/c++\ext/concurrence.h:290:7: note:
>      candidate template ignored: substitution failure [with _Rm =
>      __gthread_recursive_mutex_t]: no type named '__type' in
>      '__gnu_cxx::__enable_if<false, void>'
>      _S_destroy(_Rm* __mx)
>      ^
> 1 error generated.
>
> I am using clang 3.2 version:
>
> clang version 3.2 (trunk 157115) (llvm/trunk 157155)
> Target: i686-pc-mingw32
> Thread model: posix
>
> I'd like to know if this is a problem with my installation/gcc/build
> issue. Any help will be much appreciated.

This is a libstdc++ bug, in code which seems to be Win32-specific. The
code looks like this (around ext/concurrence.h:273):

    template<typename _Rm>
      static typename __enable_if<sizeof(&_Rm::sema), void>::__type
      _S_destroy(_Rm* __mx)

The intent appears to be to cause a substitution failure if there is
no _Rm::sema member, but the actual effect is that this is always
ill-formed in C++11 mode, since a pointer/pointer-to-member has size >
1, and thus the sizeof expression can't be narrowed to bool. You can
fix this header by casting the result of sizeof to bool:

      static typename __enable_if<(bool)sizeof(&_Rm::sema), void>::__type

I've filed this against libstdc++ as gcc.gnu.org/PR53578.




More information about the cfe-dev mailing list