PCCproject / PCC-Uspace

The userspace implementations of PCC.
BSD 3-Clause "New" or "Revised" License
119 stars 61 forks source link

MacOS make error:invalid operands to binary expression #23

Closed LiYufengzz closed 3 years ago

LiYufengzz commented 3 years ago

Hi,when I build project on my mac,some errors occurred.I don't know how to solve it.

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/functional:688:21: error: invalid operands to binary expression ('const timespec' and 'const timespec') {return x == y;}


/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/unordered_map:516:17: note: in instantiation of member function 'std::__1::equal_to<timespec>::operator()' requested here
        {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y);}
                ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__hash_table:2472:24: note: in instantiation of member function 'std::__1::__unordered_map_equal<timespec, std::__1::__hash_value_type<timespec, int>, std::__1::equal_to<timespec>, true>::operator()' requested here
                    && key_eq()(__nd->__upcast()->__value_, __k))
                       ^
y-koj commented 3 months ago

This problem also occur on Linux with g++ 14.0.1.

In my case, the problem was solved by moving oparator==() out of the std namespace in src/core/core.cpp. (I'm not sure why this change works though...)

--- core.cpp.old    2024-07-12 16:22:47.097660798 +0900
+++ core.cpp    2024-07-12 16:22:58.605841818 +0900
@@ -73,10 +73,8 @@
 // #define DEBUG_SEND_SEQ_AND_ID
 // #define DEBUG_LOSS

-namespace std {
-  int operator==(const struct timespec& ts1, const struct timespec& ts2) {
-    return ts1.tv_sec == ts2.tv_sec && ts1.tv_nsec == ts2.tv_nsec;
-  }
+int operator==(const struct timespec& ts1, const struct timespec& ts2) {
+  return ts1.tv_sec == ts2.tv_sec && ts1.tv_nsec == ts2.tv_nsec;
 }
 using namespace std;
y-koj commented 3 months ago

Linux case is caused by the equal_to function which was introduced in C++14, similar to the macOS case. The full build errors for core.cpp is as follows.

g++ -g -std=c++0x -fPIC -Wall -Wextra -DLINUX -finline-functions -O3 -fno-strict-aliasing  -DIA32 core.cpp -c
core.cpp: In member function ‘void CUDT::connect(const sockaddr*)’:
core.cpp:781:32: warning: implicitly-declared ‘CUDTException& CUDTException::operator=(const CUDTException&)’ is deprecated [-Wdeprecated-copy]
  781 |       e = CUDTException(1, 1, 0);
      |                                ^
In file included from common.h:45,
                 from cache.h:44,
                 from api.h:44,
                 from core.h:47,
                 from core.cpp:43:
udt.h:275:3: note: because ‘CUDTException’ has user-provided ‘CUDTException::CUDTException(const CUDTException&)’
  275 |   CUDTException(const CUDTException& e);
      |   ^~~~~~~~~~~~~
core.cpp:792:26: warning: implicitly-declared ‘CUDTException& CUDTException::operator=(const CUDTException&)’ is deprecated [-Wdeprecated-copy]
  792 |       e = CUDTException(1);
      |                          ^
udt.h:275:3: note: because ‘CUDTException’ has user-provided ‘CUDTException::CUDTException(const CUDTException&)’
  275 |   CUDTException(const CUDTException& e);
      |   ^~~~~~~~~~~~~
core.cpp:795:32: warning: implicitly-declared ‘CUDTException& CUDTException::operator=(const CUDTException&)’ is deprecated [-Wdeprecated-copy]
  795 |       e = CUDTException(1, 2, 0);
      |                                ^
udt.h:275:3: note: because ‘CUDTException’ has user-provided ‘CUDTException::CUDTException(const CUDTException&)’
  275 |   CUDTException(const CUDTException& e);
      |   ^~~~~~~~~~~~~
core.cpp:798:32: warning: implicitly-declared ‘CUDTException& CUDTException::operator=(const CUDTException&)’ is deprecated [-Wdeprecated-copy]
  798 |       e = CUDTException(1, 4, 0);
      |                                ^
udt.h:275:3: note: because ‘CUDTException’ has user-provided ‘CUDTException::CUDTException(const CUDTException&)’
  275 |   CUDTException(const CUDTException& e);
      |   ^~~~~~~~~~~~~
In file included from core.h:55:
packet_tracker.h: In instantiation of ‘IdType PacketTracker<SeqNoType, IdType>::MakeNewPacketId(CPacket&) [with SeqNoType = int; IdType = long unsigned int]’:
packet_tracker.h:307:33:   required from ‘void PacketTracker<SeqNoType, IdType>::OnPacketSent(CPacket&) [with SeqNoType = int; IdType = long unsigned int]’
  307 |                                 MakeNewPacketId(packet));
      |                                 ^~~~~~~~~~~~~~~
core.cpp:1847:32:   required from here
 1847 |   packet_tracker_->OnPacketSent(packet);
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
packet_tracker.h:225:67: warning: unused parameter ‘packet’ [-Wunused-parameter]
  225 | IdType PacketTracker<SeqNoType, IdType>::MakeNewPacketId(CPacket& packet) {
      |                                                          ~~~~~~~~~^~~~~~
In file included from /usr/local/include/c++/14.1.0/string:49,
                 from /usr/local/include/c++/14.1.0/bits/locale_classes.h:40,
                 from /usr/local/include/c++/14.1.0/bits/ios_base.h:41,
                 from /usr/local/include/c++/14.1.0/ios:44,
                 from /usr/local/include/c++/14.1.0/istream:40,
                 from /usr/local/include/c++/14.1.0/fstream:40,
                 from udt.h:44:
/usr/local/include/c++/14.1.0/bits/stl_function.h: In instantiation of ‘bool std::equal_to<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = timespec]’:
/usr/local/include/c++/14.1.0/bits/hashtable_policy.h:1740:16:   required from ‘bool std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_M_key_equals(const _Key&, const std::__detail::_Hash_node_value<_Value, typename _Traits::__hash_cached::value>&) const [with _Key = timespec; _Value = std::pair<const timespec, int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<timespec>; _Hash = std::hash<timespec>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>; typename _Traits::__hash_cached = std::__detail::_Hashtable_traits<true, false, true>::__hash_cached]’
 1740 |         return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/c++/14.1.0/bits/hashtable.h:1731:29:   required from ‘std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::iterator std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::find(const key_type&) [with _Key = timespec; _Value = std::pair<const timespec, int>; _Alloc = std::allocator<std::pair<const timespec, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<timespec>; _Hash = std::hash<timespec>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>; iterator = std::__detail::_Insert_base<timespec, std::pair<const timespec, int>, std::allocator<std::pair<const timespec, int> >, std::__detail::_Select1st, std::equal_to<timespec>, std::hash<timespec>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::iterator; key_type = timespec]’
 1731 |             if (this->_M_key_equals(__k, *__it))
      |                 ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
/usr/local/include/c++/14.1.0/bits/unordered_map.h:877:25:   required from ‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::find(const key_type&) [with _Key = timespec; _Tp = int; _Hash = std::hash<timespec>; _Pred = std::equal_to<timespec>; _Alloc = std::allocator<std::pair<const timespec, int> >; iterator = std::__detail::_Insert_base<timespec, std::pair<const timespec, int>, std::allocator<std::pair<const timespec, int> >, std::__detail::_Select1st, std::equal_to<timespec>, std::hash<timespec>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::iterator; key_type = timespec]’
  877 |       { return _M_h.find(__x); }
      |                ~~~~~~~~~^~~~~
packet_tracker.h:517:42:   required from ‘SeqNoType PacketTracker<SeqNoType, IdType>::GetOldestSentSeqNo() [with SeqNoType = int; IdType = long unsigned int]’
  517 |       sent_iterator = sent_time_map_.find(sent_queue_.top());
      |                       ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
core.cpp:2010:57:   required from here
 2010 |     int32_t seq_no = packet_tracker_->GetOldestSentSeqNo();
      |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/usr/local/include/c++/14.1.0/bits/stl_function.h:375:20: error: no match for ‘operator==’ (operand types are ‘const timespec’ and ‘const timespec’)
  375 |       { return __x == __y; }
      |                ~~~~^~~~~~
In file included from /usr/local/include/c++/14.1.0/iosfwd:42,
                 from /usr/local/include/c++/14.1.0/ios:40:
/usr/local/include/c++/14.1.0/bits/postypes.h:192:5: note: candidate: ‘template<class _StateT> bool std::operator==(const fpos<_StateT>&, const fpos<_StateT>&)’
  192 |     operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
      |     ^~~~~~~~
/usr/local/include/c++/14.1.0/bits/postypes.h:192:5: note:   template argument deduction/substitution failed:
/usr/local/include/c++/14.1.0/bits/stl_function.h:375:20: note:   ‘const timespec’ is not derived from ‘const std::fpos<_StateT>’
  375 |       { return __x == __y; }
      |                ~~~~^~~~~~
In file included from /usr/local/include/c++/14.1.0/string:43:
/usr/local/include/c++/14.1.0/bits/allocator.h:235:5: note: candidate: ‘template<class _T1, class _T2> bool std::operator==(const allocator<_CharT>&, const allocator<_T2>&)’
  235 |     operator==(const allocator<_T1>&, const allocator<_T2>&)
      |     ^~~~~~~~
/usr/local/include/c++/14.1.0/bits/allocator.h:235:5: note:   template argument deduction/substitution failed:
/usr/local/include/c++/14.1.0/bits/stl_function.h:375:20: note:   ‘const timespec’ is not derived from ‘const std::allocator<_CharT>’
  375 |       { return __x == __y; }
      |                ~~~~^~~~~~
In file included from /usr/local/include/c++/14.1.0/string:48:
/usr/local/include/c++/14.1.0/bits/stl_iterator.h:441:5: note: candidate: ‘template<class _Iterator> bool std::operator==(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)’
  441 |     operator==(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/local/include/c++/14.1.0/bits/stl_iterator.h:441:5: note:   template argument deduction/substitution failed:
/usr/local/include/c++/14.1.0/bits/stl_function.h:375:20: note:   ‘const timespec’ is not derived from ‘const std::reverse_iterator<_Iterator>’
  375 |       { return __x == __y; }
      |                ~~~~^~~~~~
/usr/local/include/c++/14.1.0/bits/stl_iterator.h:486:5: note: candidate: ‘template<class _IteratorL, class _IteratorR> bool std::operator==(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)’
  486 |     operator==(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/local/include/c++/14.1.0/bits/stl_iterator.h:486:5: note:   template argument deduction/substitution failed:
/usr/local/include/c++/14.1.0/bits/stl_function.h:375:20: note:   ‘const timespec’ is not derived from ‘const std::reverse_iterator<_Iterator>’
  375 |       { return __x == __y; }
      |                ~~~~^~~~~~
/usr/local/include/c++/14.1.0/bits/stl_iterator.h:1667:5: note: candidate: ‘template<class _IteratorL, class _IteratorR> bool std::operator==(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)’
 1667 |     operator==(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/local/include/c++/14.1.0/bits/stl_iterator.h:1667:5: note:   template argument deduction/substitution failed:
/usr/local/include/c++/14.1.0/bits/stl_function.h:375:20: note:   ‘const timespec’ is not derived from ‘const std::move_iterator<_IteratorL>’
  375 |       { return __x == __y; }
      |                ~~~~^~~~~~
/usr/local/include/c++/14.1.0/bits/stl_iterator.h:1737:5: note: candidate: ‘template<class _Iterator> bool std::operator==(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)’
 1737 |     operator==(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/local/include/c++/14.1.0/bits/stl_iterator.h:1737:5: note:   template argument deduction/substitution failed:
/usr/local/include/c++/14.1.0/bits/stl_function.h:375:20: note:   ‘const timespec’ is not derived from ‘const std::move_iterator<_IteratorL>’
  375 |       { return __x == __y; }
      |                ~~~~^~~~~~
In file included from ../pcc/quic_types/quic_bandwidth.h:10,
                 from ../pcc/pcc_monitor_interval_queue.h:4,
                 from ../pcc/pcc_sender.h:6,
                 from core.h:60:
../pcc/quic_types/quic_time.h:75:13: note: candidate: ‘bool operator==(QuicTime::Delta, QuicTime::Delta)’
   75 | inline bool operator==(QuicTime::Delta lhs, QuicTime::Delta rhs) {
      |             ^~~~~~~~
../pcc/quic_types/quic_time.h:75:40: note:   no known conversion for argument 1 from ‘const timespec’ to ‘QuicTime::Delta’
   75 | inline bool operator==(QuicTime::Delta lhs, QuicTime::Delta rhs) {
      |                        ~~~~~~~~~~~~~~~~^~~
../pcc/quic_types/quic_time.h:98:13: note: candidate: ‘bool operator==(QuicTime, QuicTime)’
   98 | inline bool operator==(QuicTime lhs, QuicTime rhs) {
      |             ^~~~~~~~
../pcc/quic_types/quic_time.h:98:33: note:   no known conversion for argument 1 from ‘const timespec’ to ‘QuicTime’
   98 | inline bool operator==(QuicTime lhs, QuicTime rhs) {
      |                        ~~~~~~~~~^~~
../pcc/quic_types/quic_bandwidth.h:83:13: note: candidate: ‘bool operator==(QuicBandwidth, QuicBandwidth)’
   83 | inline bool operator==(QuicBandwidth lhs, QuicBandwidth rhs) {
      |             ^~~~~~~~
../pcc/quic_types/quic_bandwidth.h:83:38: note:   no known conversion for argument 1 from ‘const timespec’ to ‘QuicBandwidth’
   83 | inline bool operator==(QuicBandwidth lhs, QuicBandwidth rhs) {
      |                        ~~~~~~~~~~~~~~^~~
In file included from ../pcc/quic_types/quic_bandwidth.h:11:
../pcc/quic_types/quic_types.h: At global scope:
../pcc/quic_types/quic_types.h:10:13: warning: ‘HAS_RETRANSMITTABLE_DATA’ defined but not used [-Wunused-variable]
   10 | static bool HAS_RETRANSMITTABLE_DATA = true;
      |             ^~~~~~~~~~~~~~~~~~~~~~~~
make: *** [Makefile:39: core.o] Error 1