2012-06-20 22 views
8

Avere il seguente codiceClang, std :: shared_ptr e std :: meno/operatore <

#include <memory> 

int main() { 
    std::shared_ptr<int> ptr0(new int); 
    std::shared_ptr<int> ptr1(new int); 

    bool result = ptr0 < ptr1; 
} 

produce il seguente errore quando viene compilato con clangore (versione 3.1, LLVM 3.1, Debian GNU/Linux Sid)

/usr/bin/../lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/shared_ptr.h:364:14: error: no matching function for call to object of type 'std::less<_CT>' 
     return std::less<_CT>()(__a.get(), __b.get()); 
      ^~~~~~~~~~~~~~~~ 
foo.cpp:9:21: note: in instantiation of function template specialization 'std::operator<<int, int>' requested here 
     bool result = ptr0 < ptr1; 
         ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/stl_function.h:236:7: note: candidate function not viable: no known conversion from 'int *' to 'int *&&&' for 
     1st argument; 
     operator()(const _Tp& __x, const _Tp& __y) const 
    ^

Compilare lo stesso codice con GCC (versione 4.7.0) non genera alcun messaggio di errore. C'è un motivo per cui l'operatore <() non funziona per i puntatori condivisi in clang?

+11

Wow, 'int * &&&' ... – kennytm

risposta

12

clang ++ e libstdC++ non corrispondono ancora perfettamente. Si potrebbe fare una delle seguenti:

  • Passa a libC++ (utilizzando clang++ -stdlib=libc++ -std=c++11 ...)
  • Applicare la seguente patch per /usr/include/c++/4.7.0/type_traits (come documentato in http://clang.llvm.org/cxx_status.html):

    Index: include/std/type_traits 
    =================================================================== 
    --- include/std/type_traits (revision 185724) 
    +++ include/std/type_traits (working copy) 
    @@ -1746,7 +1746,7 @@ 
    
        template<typename _Tp, typename _Up> 
        struct common_type<_Tp, _Up> 
    - { typedef decltype(true ? declval<_Tp>() : declval<_Up>()) type; }; 
    + { typedef typename decay<decltype(true ? declval<_Tp>() : declval<_Up>())>::type type; }; 
    
        template<typename _Tp, typename _Up, typename... _Vp> 
        struct common_type<_Tp, _Up, _Vp...> 
    

Se tu controlli bits/shared_ptr.h hai trovato uno std::common_type, e gli sviluppatori di clang sostengono che it's actually a bug of libstdc++, anche se non credo un bug di libstdC++ da solo causerebbe l'inesistente tipo int*&&& da visualizzare.

Problemi correlati