lballabio / QuantLib

The QuantLib C++ library
http://quantlib.org
Other
5k stars 1.73k forks source link

Build fails with GCC 13.2.0 because std::reverse is used without #include <algorithm> #1967

Closed tomwhoiscontrary closed 1 month ago

tomwhoiscontrary commented 1 month ago

Building 1.34, i get:

/root/QuantLib/ql/time/schedule.cpp: In constructor 'QuantLib::Schedule::Schedule(QuantLib::Date, const QuantLib::Date&, const QuantLib::Period&, QuantLib::Calendar, QuantLib::BusinessDayConvention, QuantLib::BusinessDayConvention, QuantLib::DateGeneration::Rule, bool, const QuantLib::Date&, const QuantLib::Date&)':
/root/QuantLib/ql/time/schedule.cpp:244:18: error: 'reverse' is not a member of 'std'
  244 |             std::reverse(dates_.begin(), dates_.end());
      |                  ^~~~~~~
/root/QuantLib/ql/time/schedule.cpp:245:18: error: 'reverse' is not a member of 'std'
  245 |             std::reverse(isRegular_.begin(), isRegular_.end());
      |                  ^~~~~~~
[ 79%] Building CXX object ql/CMakeFiles/ql_library.dir/utilities/dataformatters.cpp.o
make[2]: *** [ql/CMakeFiles/ql_library.dir/build.make:13380: ql/CMakeFiles/ql_library.dir/time/schedule.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:1231: ql/CMakeFiles/ql_library.dir/all] Error 2
make: *** [Makefile:166: all] Error 2

That std::reverse is here.

Your CI tests with GCC 13, so it's strange that i see this and CI didn't. It might be to do with the set of options and compiler flags i'm using. My complete cmake line is:

CXXFLAGS="-O2 -ggdb -Wall -Wno-unknown-pragmas -Werror -std=c++14 -fno-math-errno -fno-trapping-math -DBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS" cmake .. -G "Unix Makefiles" -D CMAKE_BUILD_TYPE=Release -D QL_USE_STD_CLASSES=ON -D QL_USE_INDEXED_COUPON=ON -D QL_ERROR_LINES=ON

I can fix this by adding #include <algorithm> to schedule.cpp.

I haven't tried building master, but the includes in that file haven't changed, so i'm guessing this hasn't been fixed already.

lballabio commented 1 month ago

Sure, go ahead—thanks!