Thursday, 14 November 2013

Еще одна причина использовать clang++ вместо g++


Сравните выдачу g++ при малюсенькой ошибке в шаблонах:
ip_lookup.cpp: In function ‘void insert_prefix_bitwise_tree(tree_leaf*, std::string, int)’:
ip_lookup.cpp:116:45: error: no match for ‘operator&’ in ‘std::cout.std::basic_ostream<_CharT, _Traits>::operator<< <char, std::char_traits<char> >(netmask_as_int) & (1 << i)’
ip_lookup.cpp:116:45: note: candidates are:
In file included from /usr/include/c++/4.7/ios:43:0,
                 from /usr/include/c++/4.7/ostream:40,
                 from /usr/include/c++/4.7/iostream:40,
                 from ip_lookup.cpp:1:
/usr/include/c++/4.7/bits/ios_base.h:77:3: note: std::_Ios_Fmtflags std::operator&(std::_Ios_Fmtflags, std::_Ios_Fmtflags)
/usr/include/c++/4.7/bits/ios_base.h:77:3: note:   no known conversion for argument 1 from ‘std::basic_ostream<char>::__ostream_type {aka std::basic_ostream<char>}’ to ‘std::_Ios_Fmtflags’
/usr/include/c++/4.7/bits/ios_base.h:117:3: note: std::_Ios_Openmode std::operator&(std::_Ios_Openmode, std::_Ios_Openmode)
/usr/include/c++/4.7/bits/ios_base.h:117:3: note:   no known conversion for argument 1 from ‘std::basic_ostream<char>::__ostream_type {aka std::basic_ostream<char>}’ to ‘std::_Ios_Openmode’
/usr/include/c++/4.7/bits/ios_base.h:155:3: note: std::_Ios_Iostate std::operator&(std::_Ios_Iostate, std::_Ios_Iostate)
/usr/include/c++/4.7/bits/ios_base.h:155:3: note:   no known conversion for argument 1 from ‘std::basic_ostream<char>::__ostream_type {aka std::basic_ostream<char>}’ to ‘std::_Ios_Iostate’
In file included from ip_lookup.cpp:96:0:
/usr/include/c++/4.7/bitset:1418:5: note: template<long unsigned int _Nb> std::bitset<_Nb> std::operator&(const std::bitset<_Nb>&, const std::bitset<_Nb>&)
/usr/include/c++/4.7/bitset:1418:5: note:   template argument deduction/substitution failed:
ip_lookup.cpp:116:45: note:   ‘std::basic_ostream<char>::__ostream_type {aka std::basic_ostream<char>}’ is not derived from ‘const std::bitset<_Nb>’



И выдачу clang (он ее еще посдсветил!!!):
clang ip_lookup.cpp -g -pg
ip_lookup.cpp:116:36: error: invalid operands to binary expression ('__ostream_type'
      (aka 'basic_ostream<char, std::char_traits<char> >') and 'int')
        std::cout<< netmask_as_int & (1 << i);
        ~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~
/usr/include/c++/4.6/bits/ios_base.h:76:3: note: candidate function not viable: no known conversion from '__ostream_type' (aka
      'basic_ostream<char, std::char_traits<char> >') to 'std::_Ios_Fmtflags' for 1st argument;
  operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
  ^
/usr/include/c++/4.6/bits/ios_base.h:116:3: note: candidate function not viable: no known conversion from '__ostream_type' (aka
      'basic_ostream<char, std::char_traits<char> >') to 'std::_Ios_Openmode' for 1st argument;
  operator&(_Ios_Openmode __a, _Ios_Openmode __b)
  ^
/usr/include/c++/4.6/bits/ios_base.h:154:3: note: candidate function not viable: no known conversion from '__ostream_type' (aka
      'basic_ostream<char, std::char_traits<char> >') to 'std::_Ios_Iostate' for 1st argument;
  operator&(_Ios_Iostate __a, _Ios_Iostate __b)
  ^
/usr/include/c++/4.6/bitset:1408:5: note: candidate template ignored: failed template argument deduction
    operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y)

Версии (Debian Wheezy):
clang -v
Debian clang version 3.0-6.2 (tags/RELEASE_30/final) (based on LLVM 3.0) 
gcc  --version
gcc (Debian 4.7.2-5) 4.7.2

2 comments:

  1. Укажите, пожалуйста, версии использованных GCC и Clang, для истории ;)

    ReplyDelete

Note: only a member of this blog may post a comment.