SuperTux / supertux

SuperTux source code
https://supertux.org
GNU General Public License v3.0
2.48k stars 474 forks source link

Supertux does not compile due to missing header #2937

Closed biggeryetbetter closed 2 months ago

biggeryetbetter commented 2 months ago

On the master branch (commit fa2e057) Supertux does not compile for me as of a few weeks ago. Building as usual with make will cause the following error to be produced eventually:

/home/user/Downloads/supertux/src/editor/object_settings.cpp: In member function ‘void ObjectSettings::add_path_ref(const std::string&, PathObject&, const std::string&, const std::string&, unsigned int)’:
/home/user/Downloads/supertux/src/editor/object_settings.cpp:248:26: error: ‘remove_if’ is not a member of ‘std’; did you mean ‘remove_cv’?
  248 |     m_options.erase(std::remove_if(m_options.begin(), m_options.end(),
      |                          ^~~~~~~~~
      |                          remove_cv
/home/user/Downloads/supertux/src/editor/object_settings.cpp: In member function ‘void ObjectSettings::reorder(const std::vector<std::__cxx11::basic_string<char> >&)’:
/home/user/Downloads/supertux/src/editor/object_settings.cpp:361:26: error: no matching function for call to ‘find(std::vector<std::__cxx11::basic_string<char> >::const_iterator, std::vector<std::__cxx11::basic_string<char> >::const_iterator, const std::string&)’
  361 |       auto it = std::find(order.begin(), order.end(), option->get_key());
      |                 ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14.1.1/bits/locale_facets.h:48,
                 from /usr/include/c++/14.1.1/locale:42,
                 from /usr/include/glm/gtx/io.hpp:40,
                 from /usr/include/glm/ext.hpp:224,
                 from /home/user/Downloads/supertux/src/math/vector.hpp:23,
                 from /home/user/Downloads/supertux/src/math/sizef.hpp:22,
                 from /home/user/Downloads/supertux/src/object/path_walker.hpp:23,
                 from /home/user/Downloads/supertux/src/editor/object_option.hpp:27,
                 from /home/user/Downloads/supertux/src/editor/object_settings.hpp:23,
                 from /home/user/Downloads/supertux/src/editor/object_settings.cpp:17:
/usr/include/c++/14.1.1/bits/streambuf_iterator.h:435:5: note: candidate: ‘template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> > >::__type std::find(istreambuf_iterator<_CharT, char_traits<_CharT> >, istreambuf_iterator<_CharT, char_traits<_CharT> >, const _CharT2&)’
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14.1.1/bits/streambuf_iterator.h:435:5: note:   template argument deduction/substitution failed:
/home/user/Downloads/supertux/src/editor/object_settings.cpp:361:26: note:   ‘__gnu_cxx::__normal_iterator<const std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >’ is not derived from ‘std::istreambuf_iterator<_CharT, std::char_traits<_CharT> >’
  361 |       auto it = std::find(order.begin(), order.end(), option->get_key());
      |                 ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/Downloads/supertux/src/editor/object_settings.cpp:371:20: error: ‘find_if’ is not a member of ‘std’; did you mean ‘find’?
  371 |     auto it = std::find_if(m_options.begin(), m_options.end(),
      |                    ^~~~~~~
      |                    find
/home/user/Downloads/supertux/src/editor/object_settings.cpp: In member function ‘void ObjectSettings::remove(const std::string&)’:
/home/user/Downloads/supertux/src/editor/object_settings.cpp:388:24: error: ‘remove_if’ is not a member of ‘std’; did you mean ‘remove_cv’?
  388 |   m_options.erase(std::remove_if(m_options.begin(), m_options.end(),
      |                        ^~~~~~~~~
      |                        remove_cv
make[2]: *** [CMakeFiles/supertux2_lib.dir/build.make:1505: CMakeFiles/supertux2_lib.dir/src/editor/object_settings.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:287: CMakeFiles/supertux2_lib.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

This is presumably due to the <algorithm> header not being included in this file for whatever reason.

tobbi commented 2 months ago

Can you add #include <algorithm> to the top of the file src/editor/object_settings.cpp and see if that fixes it?

tulpenkiste commented 2 months ago

Can you add #include <algorithm> to the top of the file src/editor/object_settings.cpp and see if that fixes it?

Just tested this on my end, adding this include fixes the problem

biggeryetbetter commented 2 months ago

Can you add #include <algorithm> to the top of the file src/editor/object_settings.cpp and see if that fixes it?

Yep, this fixes it. Do you want me to make a pull request for this or would you be able to just commit it straight to master? This is a pretty trivial change.

tobbi commented 2 months ago

Sure, just make a pull request. One less thing for me to think about.

tobbi commented 2 months ago

I don't quite understand how I've never experienced this bug on my system before.

ztianyang commented 2 months ago

I don't quite understand how I've never experienced this bug on my system before.

I think this is because of the version of gcc being used. The latest version of gcc on my Arch Linux system is 14.1.1. I recently experienced a similar issue when compiling Minetest 5.8.0, and I worked around this issue by installing the gcc13 package and using g++-13 as the c++ compiler. I was able to replicate this error in SuperTux using gcc 14. This error does not appear when I use gcc 13.

biggeryetbetter commented 2 months ago

I was able to replicate this error in SuperTux using gcc 14.

I'm also running an Arch system and sure enough, I've got GCC 14 installed. I wonder if something changed in how it handles transitive includes.