2012-02-03 5 views
5

मैंने एक गैर-प्रतिलिपि बनाने योग्य मानचित्र बनाया है जिसे मैं क्लैंग के साथ संकलित नहीं कर सकता। चूंकि क्लैंग बहुत मानक मानने के लिए है, इसलिए मैं सोच रहा था कि मेरा कोड कानूनी था या नहीं। एमएसवीएस 2010 और जीसीसी 4.7 चेतावनियों या त्रुटियों के बिना इस कोड को संकलित करें।क्या यह गैर-कॉपी करने योग्य मानचित्र कानूनी C++ 11 है? जीसीसी 4.7 और एमएसवीएस 2010 इसे अनुमति देते हैं। Clang 3.1

पूर्ण कोड संलग्न है: समस्याग्रस्त रेखा main की अंतिम पंक्ति है।

= delete

#include <utility> 
#include <iostream> 
#include <map> 

template<typename Key_t, typename Value_t, typename Compare_t = std::less<Key_t> > 
class non_copyable_map : public std::map<Key_t,Value_t,Compare_t> 
{ 
    typedef std::map<Key_t,Value_t,Compare_t> BaseType; 

    public: 
    non_copyable_map() { } 

    non_copyable_map(non_copyable_map&& t) : BaseType(std::move(t)) {} 

    non_copyable_map& operator = (non_copyable_map&& t) 
    { 
     if (this != &t) 
     { 
     std::swap<BaseType>(*this,t); 
     } 
     return *this; 
    } 

    private: 
    non_copyable_map(const non_copyable_map&) = delete; 
    non_copyable_map& operator = (const non_copyable_map&) = delete; 
}; 

int main(int argc, char* argv[]) 
{ 
    non_copyable_map<int, non_copyable_map<int, int> > nestedMap; 
    non_copyable_map<int,int> inner; 
    inner[3]=4; 
    nestedMap[2] = std::move(inner); // THIS LINE CAUSES CLANG PROBLEMS 
} 

जब clang++-mp-3.1 -std=c++0x -stdlib=libc++ MapOfMaps.cpp का उपयोग कर MSVS 2010

के लिए निकालने में त्रुटि संदेश की जरूरत है:

In file included from MapOfMaps.cpp:2: 
In file included from /usr/include/c++/v1/iostream:40: 
In file included from /usr/include/c++/v1/istream:156: 
In file included from /usr/include/c++/v1/ostream:134: 
In file included from /usr/include/c++/v1/bitset:118: 
/usr/include/c++/v1/__bit_reference:26:26: error: no type named '__storage_type' in 
     'std::__1::map<int, int, std::__1::less<int>, std::__1::allocator<std::__1::pair<const 
     int, int> > >' 
    typedef typename _C::__storage_type __storage_type; 
      ~~~~~~~~~~~~~^~~~~~~~~~~~~~ 
MapOfMaps.cpp:21:25: note: in instantiation of template class 
     'std::__1::__bit_reference<std::__1::map<int, int, std::__1::less<int>, 
     std::__1::allocator<std::__1::pair<const int, int> > > >' requested here 
           std::swap<BaseType>(*this,t); 
                ^
MapOfMaps.cpp:36:15: note: in instantiation of member function 'non_copyable_map<int, int, 
     std::__1::less<int> >::operator=' requested here 
     nestedMap[2] = std::move(inner); 
        ^
In file included from MapOfMaps.cpp:2: 
In file included from /usr/include/c++/v1/iostream:40: 
In file included from /usr/include/c++/v1/istream:156: 
In file included from /usr/include/c++/v1/ostream:134: 
In file included from /usr/include/c++/v1/bitset:118: 
/usr/include/c++/v1/__bit_reference:27:26: error: no type named '__storage_pointer' in 
     'std::__1::map<int, int, std::__1::less<int>, std::__1::allocator<std::__1::pair<const 
     int, int> > >' 
    typedef typename _C::__storage_pointer __storage_pointer; 
      ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ 
/usr/include/c++/v1/__bit_reference:33:25: error: no type named '__self' in 
     'std::__1::map<int, int, std::__1::less<int>, std::__1::allocator<std::__1::pair<const 
     int, int> > >' 
    friend typename _C::__self; 
      ~~~~~~~~~~~~~^~~~~~ 
In file included from MapOfMaps.cpp:3: 
In file included from /usr/include/c++/v1/map:338: 
/usr/include/c++/v1/__tree:1291:14: error: overload resolution selected deleted operator '=' 
    __pair3_ = _STD::move(__t.__pair3_); 
    ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ 
/usr/include/c++/v1/__tree:1308:9: note: in instantiation of member function 
     'std::__1::__tree<std::__1::pair<int, int>, std::__1::__map_value_compare<int, int, 
     std::__1::less<int>, true>, std::__1::allocator<std::__1::pair<int, int> > 
     >::__move_assign' requested here 
     __move_assign(__t, true_type()); 
     ^
/usr/include/c++/v1/__tree:1353:5: note: in instantiation of member function 
     'std::__1::__tree<std::__1::pair<int, int>, std::__1::__map_value_compare<int, int, 
     std::__1::less<int>, true>, std::__1::allocator<std::__1::pair<int, int> > 
     >::__move_assign' requested here 
    __move_assign(__t, integral_constant<bool, 
    ^
/usr/include/c++/v1/map:736:21: note: in instantiation of member function 
     'std::__1::__tree<std::__1::pair<int, int>, std::__1::__map_value_compare<int, int, 
     std::__1::less<int>, true>, std::__1::allocator<std::__1::pair<int, int> > >::operator=' 
     requested here 
      __tree_ = _STD::move(__m.__tree_); 
        ^
/usr/include/c++/v1/type_traits:2342:9: note: in instantiation of member function 
     'std::__1::map<int, int, std::__1::less<int>, std::__1::allocator<std::__1::pair<const 
     int, int> > >::operator=' requested here 
    __x = _STD::move(__y); 
     ^
MapOfMaps.cpp:21:5: note: in instantiation of function template specialization 
     'std::__1::swap<std::__1::map<int, int, std::__1::less<int>, 
     std::__1::allocator<std::__1::pair<const int, int> > > >' requested here 
           std::swap<BaseType>(*this,t); 
           ^
MapOfMaps.cpp:36:15: note: in instantiation of member function 'non_copyable_map<int, int, 
     std::__1::less<int> >::operator=' requested here 
     nestedMap[2] = std::move(inner); 
        ^
/usr/include/c++/v1/memory:1918:7: note: candidate function (the implicit copy assignment 
     operator) has been explicitly deleted 
class __compressed_pair 
    ^
4 errors generated. 
+0

आपको कौन सा विशिष्ट त्रुटि संदेश मिल रहा है? – templatetypedef

+0

मैंने प्रारंभिक पोस्ट – jbcoe

उत्तर

1

यह एक बजना या libC++ बग (सबसे अधिक संभावना libC++) हो सकता है। मैं टिप-ऑफ-ट्रंक टूल के साथ अपने लक्षण को डुप्लिकेट नहीं कर रहा हूं। नवीनतम libC++ शीर्षलेख here हैं। यह अंधेरे में एक शॉट का एक सा है, लेकिन इस प्रयास करें:

swap(static_cast<BaseType&>(*this),static_cast<BaseType&>(t)); 

ऐसा लगता है कि आप के साथ उलझ कर रहे इस swap<__bit_reference> में:

template <class _Cp, class _Dp> 
_LIBCPP_INLINE_VISIBILITY inline 
void 
swap(__bit_reference<_Cp> __x, __bit_reference<_Dp> __y) _NOEXCEPT 

जिसके साथ कोई संबंध नहीं है नक्शे। यह सिर्फ गुंजाइश में होता है।

+0

के नीचे त्रुटियों को जोड़ा है, जिसने समस्या को ठीक किया है। धन्यवाद। किसी भी विचार से '<__ bit_reference>' में 'स्वैप' के साथ उलझन का कारण क्या था? – jbcoe

+0

मैंने थोड़ा स्पेलंकिंग किया (बहुत कम, कुछ मिनट) और इस पर भाग गया: http://llvm.org/bugs/show_bug.cgi?id=10248 यह आपके मामले के समान दिखता है, और वहां मैं बहस कर रहा हूं आपका कोड nonconforming है, या होना चाहिए (मुझे लगता है कि इसे एक स्पष्ट टेम्पलेट पैरामीटर के साथ कॉल करने के कारण)। आपको यह बताने के लिए कि मैंने लिखा है कि 7 महीने हो चुके हैं, और मैं इस शाम को विवरण याद नहीं कर सकता (मेरा दिमाग कहीं और व्यस्त है)। फिर भी मैंने उस समय __bit_reference पर स्वैप की रक्षा के लिए स्टॉप-गैप उपाय में चेक किया, और ऐसा लगता है कि टिप-ऑफ-ट्रंक कोड की सुरक्षा क्या है। –

संबंधित मुद्दे