2017-02-01 17 views
5
struct Y { }; 
struct X : std::tuple<Y> { }; 

int main() 
{ 
    std::get<0>(std::make_tuple(X{})); 
} 

on wandbox`std :: tuple` पर` std :: tuple` पर 'std :: get` को कॉल करना' std :: tuple` से प्राप्त तत्वों के साथ - बीमार गठित?


उपरोक्त कोड को संकलित करता है और जब libC++ का उपयोग कर clang++ साथ की उम्मीद के रूप में काम करता है।

ऊपर कोड जब निम्न त्रुटि के साथ libstdC++ का उपयोग कर दोनों clang++ और g++ साथ संकलित करने के लिए विफल रहता है:

include/c++/7.0.1/tuple:1302:36: 
error: no matching function for call to ‘__get_helper<0>(std::tuple<X>&)’ 
    { return std::__get_helper<__i>(__t); } 
      ~~~~~~~~~~~~~~~~~~~~~~^~~~~ 

include/c++/7.0.1/tuple:1290:5: 
note: candidate: template<long unsigned int __i, class _Head, class ... _Tail> 
       constexpr _Head& std::__get_helper(std::_Tuple_impl<_Idx, _Head, _Tail ...>&) 
    __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept 
    ^~~~~~~~~~~~ 

include/c++/7.0.1/tuple:1290:5: 
note: template argument deduction/substitution failed: 
include/c++/7.0.1/tuple:1302:36: 
note: ‘std::_Tuple_impl<0, _Head, _Tail ...>’ is an ambiguous base class of ‘std::tuple<X>’ 
    { return std::__get_helper<__i>(__t); } 
      ~~~~~~~~~~~~~~~~~~~~~~^~~~~ 

include/c++/7.0.1/tuple:1295:5: 
note: candidate: template<long unsigned int __i, class _Head, class ... _Tail> 
       constexpr const _Head& std::__get_helper(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&) 
    __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept 
    ^~~~~~~~~~~~ 

include/c++/7.0.1/tuple:1295:5: 
note: template argument deduction/substitution failed: 
include/c++/7.0.1/tuple:1302:36: 
note: ‘const std::_Tuple_impl<0, _Head, _Tail ...>’ is an ambiguous base class of ‘std::tuple<X>’ 
    { return std::__get_helper<__i>(__t); } 
      ~~~~~~~~~~~~~~~~~~~~~~^~~~~ 

ऐसा लगता है कि libstdC++ की जब टपल std::tuple कारणों अस्पष्टता की विरासत आधारित कार्यान्वयन पर कॉल करने पर तत्व std::tuple से प्राप्त होते हैं। मुझे लगता है कि यह libstdC++ में कार्यान्वयन दोष है - क्या यह मामला है? या क्या मानक में कुछ ऐसा है जो कोड स्निपेट को खराब बना देगा?

+6

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71096 –

उत्तर

2

टिप्पणियों में T.C. द्वारा उल्लिखित अनुसार, यह known bug #71096 के कारण होता है।

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