A unique_ptr problem with clang on MinGW

A patch has been submitted by Jonathan Wakely on 06/15 and this should be fixed on trunk.

The following:

int main() {
 using namespace std;
 unique_ptr up( new int( 30 ) );


$ 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'
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
      _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
      _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

This wasn’t reproducible on the gcc versions I use, namely 4.6.2 and 4.7.0. Richard Smith was kind enough to investigate and found this was an issue with a SFINAE failure in libstdc++. (Richard has filed a bug against this!)

The workaround seems to be patching the appropriate header (ext/concurrence.h:273) yourself. There are two approaches:

  • Richard’s suggestion:
                         static typename __enable_if<(bool)sizeof(&_Rm::sema), void>::__type
  • If you don’t prefer casts:
                         static typename __enable_if::__type
About these ads

About this entry