2012-06-20 26 views
8

は打ち鳴らす(バージョン3.1、LLVM 3.1、DebianのGNU/LinuxのSID)を使用してコンパイルされたときに、次のエラーを生成しますクラン、STD ::のshared_ptrとstd ::未満/オペレータ<

/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 
    ^

同じコードをGCC(バージョン4.7.0)でコンパイルしてもエラーメッセージは表示されません。演算子<()がclangの共有ポインタに対して機能しない理由はありますか?

+11

うわー、 'int * &&&' ... – kennytm

答えて

12

clang ++とlibstdC++が完全に一致しません。

は(http://clang.llvm.org/cxx_status.htmlに記載されているように)/usr/include/c++/4.7.0/type_traitsに以下のパッチを適用します

  • clang++ -stdlib=libc++ -std=c++11 ...を使用して)++をlibcに

    • スイッチ:あなたは、次のいずれかを行うことができ

      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...> 
      

    をした場合あなたはstd::common_typeを見つけました。bits/shared_ptr.hを確認しました。そしてclangの開発者はit's actually a bug of libstdc++と主張していますが、libstdC++だけのバグは信じられません存在しないタイプint*&&&が表示されます。

  • 関連する問題