Author Topic: error: static assertion failed: comparison object must be invocable as const  (Read 2357 times)

Offline fortidet

  • Single posting newcomer
  • *
  • Posts: 3
Hi!

On building 20.03 release I get an error:

Code
In file included from /usr/include/c++/13/map:62,
                 from ./manager.h:9,
                 from ./cbplugin.h:17,
                 from ./sdk_common.h:110,
                 from ./sdk_precomp.h:13,
                 from ./sdk.h:17:
/usr/include/c++/13/bits/stl_tree.h: In instantiation of 'static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(_Const_Link_type) [with _Key = ProjectFile*; _Val = ProjectFile*; _KeyOfValue = std::_Identity<ProjectFile*>; _Compare = TargetFilesData::compareLess; _Alloc = std::allocator<ProjectFile*>; _Const_Link_type = const std::_Rb_tree_node<ProjectFile*>*]':
/usr/include/c++/13/bits/stl_tree.h:2118:47:   required from 'std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = ProjectFile*; _Val = ProjectFile*; _KeyOfValue = std::_Identity<ProjectFile*>; _Compare = TargetFilesData::compareLess; _Alloc = std::allocator<ProjectFile*>; key_type = ProjectFile*]'
/usr/include/c++/13/bits/stl_tree.h:2171:4:   required from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = ProjectFile* const&; _Key = ProjectFile*; _Val = ProjectFile*; _KeyOfValue = std::_Identity<ProjectFile*>; _Compare = TargetFilesData::compareLess; _Alloc = std::allocator<ProjectFile*>]'
/usr/include/c++/13/bits/stl_set.h:514:25:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = ProjectFile*; _Compare = TargetFilesData::compareLess; _Alloc = std::allocator<ProjectFile*>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<ProjectFile*, ProjectFile*, std::_Identity<ProjectFile*>, TargetFilesData::compareLess, std::allocator<ProjectFile*> >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<ProjectFile*>; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<ProjectFile*>, ProjectFile*>::rebind<ProjectFile*>; typename _Alloc::value_type = ProjectFile*; value_type = ProjectFile*]'
openfileslistplugin.cpp:440:57:   required from here
/usr/include/c++/13/bits/stl_tree.h:772:15: error: static assertion failed: comparison object must be invocable as const
  772 |               is_invocable_v<const _Compare&, const _Key&, const _Key&>,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_tree.h:772:15: note: 'std::is_invocable_v<const TargetFilesData::compareLess&, ProjectFile* const&, ProjectFile* const&>' evaluates to false


uname -a
Linux fedora 6.6.3-100.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 28 20:36:17 UTC 2023 x86_64 GNU/Linux

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1634
Starting with C++17 constness of the comparison operands is enforced.

Can you test if changing this (in openfileslistplugin.h:25)
Code
    typedef std::set<ProjectFile*, std::less<ProjectFile*>> OpenFilesSet;
to this
Code
    typedef std::set<const ProjectFile*, std::less<const ProjectFile*>> OpenFilesSet;
fixes compilation?

Offline fortidet

  • Single posting newcomer
  • *
  • Posts: 3
Hi!
Then it becomes even weirder:

Code
depbase=`echo openfileslistplugin.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\
/bin/sh ../../../libtool  --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -I../../../src/include  -I/usr/lib64/wx/include/gtk3-unicode-3.0 -I/usr/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -pthread -I../../../src/include -I../../../src/sdk/wxscintilla/include -DCB_AUTOCONF  -DCB_PRECOMP -DPIC -I../../../src/include/tinyxml -DTIXML_USE_STL=YES  -O2 -ffast-math  -Winvalid-pch -fPIC -fexceptions -MT openfileslistplugin.lo -MD -MP -MF $depbase.Tpo -c -o openfileslistplugin.lo openfileslistplugin.cpp &&\
mv -f $depbase.Tpo $depbase.Plo
libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I../../../src/include -I/usr/lib64/wx/include/gtk3-unicode-3.0 -I/usr/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -pthread -I../../../src/include -I../../../src/sdk/wxscintilla/include -DCB_AUTOCONF -DCB_PRECOMP -DPIC -I../../../src/include/tinyxml -DTIXML_USE_STL=YES -O2 -ffast-math -Winvalid-pch -fPIC -fexceptions -MT openfileslistplugin.lo -MD -MP -MF .deps/openfileslistplugin.Tpo -c openfileslistplugin.cpp  -fPIC -DPIC -o .libs/openfileslistplugin.o
In file included from /usr/include/c++/13/map:62,
                 from ./manager.h:9,
                 from ./cbplugin.h:17,
                 from ./sdk_common.h:110,
                 from ./sdk_precomp.h:13,
                 from ./sdk.h:17:
/usr/include/c++/13/bits/stl_tree.h: In instantiation of 'std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = const ProjectFile*; _Val = const ProjectFile*; _KeyOfValue = std::_Identity<const ProjectFile*>; _Compare = const TargetFilesData::compareLess; _Alloc = std::allocator<const ProjectFile*>; key_type = const ProjectFile*]':
/usr/include/c++/13/bits/stl_tree.h: In instantiation of 'std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = const ProjectFile*; _Val = const ProjectFile*; _KeyOfValue = std::_Identity<const ProjectFile*>; _Compare = const TargetFilesData::compareLess; _Alloc = std::allocator<const ProjectFile*>; key_type = const ProjectFile*]':
/usr/include/c++/13/bits/stl_tree.h:2171:4:   required from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = const ProjectFile* const&; _Key = const ProjectFile*; _Val = const ProjectFile*; _KeyOfValue = std::_Identity<const ProjectFile*>; _Compare = const TargetFilesData::compareLess; _Alloc = std::allocator<const ProjectFile*>]'
/usr/include/c++/13/bits/stl_set.h:514:25:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = const ProjectFile*; _Compare = const TargetFilesData::compareLess; _Alloc = std::allocator<const ProjectFile*>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<const ProjectFile*, const ProjectFile*, std::_Identity<const ProjectFile*>, const TargetFilesData::compareLess, std::allocator<const ProjectFile*> >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<const ProjectFile*>; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<const ProjectFile*>, const ProjectFile*>::rebind<const ProjectFile*>; typename _Alloc::value_type = const ProjectFile*; value_type = const ProjectFile*]'
openfileslistplugin.cpp:440:57:   required from here
/usr/include/c++/13/bits/stl_tree.h:2118:42: error: no match for call to '(const TargetFilesData::compareLess) (const ProjectFile* const&, const ProjectFile* const&)'
 2118 |           __comp = _M_impl._M_key_compare(__k, _S_key(__x));
      |                    ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
In file included from openfileslistplugin.cpp:31:
openfileslistplugin.h:26:14: note: candidate: 'bool TargetFilesData::compareLess::operator()(const ProjectFile*, const ProjectFile*)' (near match)
   26 |         bool operator()(const ProjectFile* lhs, const ProjectFile* rhs) { return lhs->editorTabPos < rhs->editorTabPos; }
      |              ^~~~~~~~
openfileslistplugin.h:26:14: note:   passing 'const TargetFilesData::compareLess*' as 'this' argument discards qualifiers
/usr/include/c++/13/bits/stl_tree.h:2129:33: error: no match for call to '(const TargetFilesData::compareLess) (const ProjectFile* const&, const ProjectFile* const&)'
 2129 |       if (_M_impl._M_key_compare(_S_key(__j._M_node), __k))
      |           ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
openfileslistplugin.h:26:14: note: candidate: 'bool TargetFilesData::compareLess::operator()(const ProjectFile*, const ProjectFile*)' (near match)
   26 |         bool operator()(const ProjectFile* lhs, const ProjectFile* rhs) { return lhs->editorTabPos < rhs->editorTabPos; }
      |              ^~~~~~~~
openfileslistplugin.h:26:14: note:   passing 'const TargetFilesData::compareLess*' as 'this' argument discards qualifiers
/usr/include/c++/13/bits/stl_tree.h: In instantiation of 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_(_Base_ptr, _Base_ptr, _Arg&&, _NodeGen&) [with _Arg = const ProjectFile* const&; _NodeGen = std::_Rb_tree<const ProjectFile*, const ProjectFile*, std::_Identity<const ProjectFile*>, const TargetFilesData::compareLess, std::allocator<const ProjectFile*> >::_Alloc_node; _Key = const ProjectFile*; _Val = const ProjectFile*; _KeyOfValue = std::_Identity<const ProjectFile*>; _Compare = const TargetFilesData::compareLess; _Alloc = std::allocator<const ProjectFile*>; iterator = std::_Rb_tree<const ProjectFile*, const ProjectFile*, std::_Identity<const ProjectFile*>, const TargetFilesData::compareLess, std::allocator<const ProjectFile*> >::iterator; _Base_ptr = std::_Rb_tree_node_base*]':
/usr/include/c++/13/bits/stl_tree.h:2176:26:   required from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = const ProjectFile* const&; _Key = const ProjectFile*; _Val = const ProjectFile*; _KeyOfValue = std::_Identity<const ProjectFile*>; _Compare = const TargetFilesData::compareLess; _Alloc = std::allocator<const ProjectFile*>]'
/usr/include/c++/13/bits/stl_set.h:514:25:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = const ProjectFile*; _Compare = const TargetFilesData::compareLess; _Alloc = std::allocator<const ProjectFile*>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<const ProjectFile*, const ProjectFile*, std::_Identity<const ProjectFile*>, const TargetFilesData::compareLess, std::allocator<const ProjectFile*> >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<const ProjectFile*>; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<const ProjectFile*>, const ProjectFile*>::rebind<const ProjectFile*>; typename _Alloc::value_type = const ProjectFile*; value_type = const ProjectFile*]'
openfileslistplugin.cpp:440:57:   required from here
/usr/include/c++/13/bits/stl_tree.h:1828:56: error: no match for call to '(const TargetFilesData::compareLess) (const ProjectFile* const&, const ProjectFile* const&)'
 1828 |                               || _M_impl._M_key_compare(_KeyOfValue()(__v),
      |                                  ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
 1829 |                                                         _S_key(__p)));
      |                                                         ~~~~~~~~~~~~
openfileslistplugin.h:26:14: note: candidate: 'bool TargetFilesData::compareLess::operator()(const ProjectFile*, const ProjectFile*)' (near match)
   26 |         bool operator()(const ProjectFile* lhs, const ProjectFile* rhs) { return lhs->editorTabPos < rhs->editorTabPos; }
      |              ^~~~~~~~
openfileslistplugin.h:26:14: note:   passing 'const TargetFilesData::compareLess*' as 'this' argument discards qualifiers
/usr/include/c++/13/bits/stl_tree.h: In instantiation of 'static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(_Const_Link_type) [with _Key = const ProjectFile*; _Val = const ProjectFile*; _KeyOfValue = std::_Identity<const ProjectFile*>; _Compare = const TargetFilesData::compareLess; _Alloc = std::allocator<const ProjectFile*>; _Const_Link_type = const std::_Rb_tree_node<const ProjectFile*>*]':
/usr/include/c++/13/bits/stl_tree.h:2118:47:   required from 'std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = const ProjectFile*; _Val = const ProjectFile*; _KeyOfValue = std::_Identity<const ProjectFile*>; _Compare = const TargetFilesData::compareLess; _Alloc = std::allocator<const ProjectFile*>; key_type = const ProjectFile*]'
/usr/include/c++/13/bits/stl_tree.h:2171:4:   required from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = const ProjectFile* const&; _Key = const ProjectFile*; _Val = const ProjectFile*; _KeyOfValue = std::_Identity<const ProjectFile*>; _Compare = const TargetFilesData::compareLess; _Alloc = std::allocator<const ProjectFile*>]'
/usr/include/c++/13/bits/stl_set.h:514:25:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = const ProjectFile*; _Compare = const TargetFilesData::compareLess; _Alloc = std::allocator<const ProjectFile*>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<const ProjectFile*, const ProjectFile*, std::_Identity<const ProjectFile*>, const TargetFilesData::compareLess, std::allocator<const ProjectFile*> >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<const ProjectFile*>; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<const ProjectFile*>, const ProjectFile*>::rebind<const ProjectFile*>; typename _Alloc::value_type = const ProjectFile*; value_type = const ProjectFile*]'
openfileslistplugin.cpp:440:57:   required from here
/usr/include/c++/13/bits/stl_tree.h:764:23: error: static assertion failed: comparison object must be invocable with two arguments of key type
  764 |         static_assert(__is_invocable<_Compare&, const _Key&, const _Key&>{},
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_tree.h:764:23: note: 'std::__is_invocable<const TargetFilesData::compareLess&, const ProjectFile* const&, const ProjectFile* const&>()' evaluates to false


Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1634
Thanks for checking. The std::less is not needed as it is the default comparison object. Can you try just
Code
    typedef std::set <ProjectFile*> OpenFilesSet;

Offline fortidet

  • Single posting newcomer
  • *
  • Posts: 3
Thanks so much!
After additionally installing boost-devel (which hasn`t been checked during configuration), compilation succeed!