0

I am trying to compile some piece of code referencing QuantLib, using Visual Studio 2017 and the Microsoft C++ compiler.

Whilst I do not get any specific compilation error flagged in the code I've written, I am stuck with the following compilation error:

Error C2676: binary '<': 'const _Ty' does not define this operator or a conversion to a type acceptable to the predefined operator

Visual Studio seems to point to the implementation of the templated std::min() function, found at line 5426 in the algorithm file:

c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\algorithm 5426

However, the full output stack from Visual Studio is as follows - and more specifically, it points to the placeholders.hpp header for boost, as well as the fact that QuantLib::Date seems to be involved:

1>QLTest.cpp
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\algorithm(5426): error C2676: binary '<': 'const _Ty' does not define this operator or a conversion to a type acceptable to the predefined operator
1>        with
1>        [
1>            _Ty=QuantLib::Date
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\algorithm(5425): note: see reference to function template instantiation 'const _Ty &std::min<QuantLib::Date>(const _Ty &,const _Ty &) noexcept(<expr>)' being compiled
1>        with
1>        [
1>            _Ty=QuantLib::Date
1>        ]
1>c:\local\boost_1_76_0\boost\bind\placeholders.hpp(66): note: see reference to class template instantiation 'boost::arg<9>' being compiled
1>c:\local\boost_1_76_0\boost\bind\placeholders.hpp(65): note: see reference to class template instantiation 'boost::arg<8>' being compiled
1>c:\local\boost_1_76_0\boost\bind\placeholders.hpp(64): note: see reference to class template instantiation 'boost::arg<7>' being compiled
1>c:\local\boost_1_76_0\boost\bind\placeholders.hpp(63): note: see reference to class template instantiation 'boost::arg<6>' being compiled
1>c:\local\boost_1_76_0\boost\bind\placeholders.hpp(62): note: see reference to class template instantiation 'boost::arg<5>' being compiled
1>c:\local\boost_1_76_0\boost\bind\placeholders.hpp(61): note: see reference to class template instantiation 'boost::arg<4>' being compiled
1>c:\local\boost_1_76_0\boost\bind\placeholders.hpp(60): note: see reference to class template instantiation 'boost::arg<3>' being compiled
1>c:\local\boost_1_76_0\boost\bind\placeholders.hpp(59): note: see reference to class template instantiation 'boost::arg<2>' being compiled
1>c:\local\boost_1_76_0\boost\bind\placeholders.hpp(58): note: see reference to class template instantiation 'boost::arg<1>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\algorithm(5426): error C2056: illegal expression

I am not sure I understand the issue here, especially because QuantLib::Date indeed implements overloads for the binary < operator.

EDIT 14 Jul 2021:

Here is a minimal piece of code that reproduces the compilation error on my side - I have collated the various include and using statements throughout the headers in my code in a single place. Also note that I have removed the using namespace std as suggested, but the error remained:

#ifdef BOOST_MSVC
#    include <ql/auto_link.hpp>
#endif

#include <ql/termstructures/yieldtermstructure.hpp>
#include <ql/math/interpolations/cubicinterpolation.hpp>
#include <ql/math/interpolations/backwardflatinterpolation.hpp>
#include <ql/math/optimization/simplex.hpp>
#include <ql/math/integrals/gausslobattointegral.hpp>
#include <ql/termstructures/yield/discountcurve.hpp>
#include <ql/interestrate.hpp>
#include <string>
#include <iostream>

#include <ql/quantlib.hpp>
#include <ql/qldefines.hpp>
#include <ql/termstructures/iterativebootstrap.hpp>
#include <ql/termstructures/yield/piecewiseyieldcurve.hpp>
#include <ql/termstructures/yieldtermstructure.hpp>
#include <ql/termstructures/yield/ratehelpers.hpp>
#include <ql/time/daycounters/actual360.hpp>
#include <ql/time/daycounters/thirty360.hpp>

#include <ql/math/distributions/normaldistribution.hpp>
#include <ql/math/solvers1d/newton.hpp>

#include <ql/math/interpolations/linearinterpolation.hpp>
#include <ql/termstructures/ErisRangeFitting.hpp>

#include <map>
#include <vector>
#include <exception>
#include <filesystem>

#include <ql/indexes/ibor/fedfunds.hpp>
#include <ql/indexes/ibor/sofr.hpp>
#include <ql/indexes/ibor/usdlibor.hpp>
#include <ql/math/interpolations/all.hpp>
#include <ql/termstructures/iterativebootstrap.hpp>
#include <ql/instruments/bonds/fixedratebond.hpp>
#include <ql/math/integrals/trapezoidintegral.hpp>
#include <ql/pricingengines/bond/bondfunctions.hpp>
#include <ql/time/calendars/jointcalendar.hpp>
#include <ql/time/calendars/unitedkingdom.hpp>
#include <ql/time/calendars/unitedstates.hpp>
#include <ql/time/daycounters/actualactual.hpp>
#include <ql/time/imm.hpp>
#include <ctime>
#include <iomanip>

#include <ql\termstructures\yield\fittedbonddiscountcurve.hpp>
#include <ql\termstructures\yield\nonlinearfittingmethods.hpp>
#include <ql\termstructures\yield\piecewiseyieldcurve.hpp>
#include <sys/stat.h>

using namespace QuantLib;

int main()
{

}
bolts
  • 1
  • 1
  • Do you have a `using namespace std;` line in your code? That would cause the use of `std::min` when (perhaps) a more specific implementation of `min` should be used by the header causing the error. – Adrian Mole Jul 07 '21 at 10:27
  • Indeed I have ```using namespace std``` in my code - however, the ```placeholders.hpp``` header from ```boost``` is not calling any ```min``` function, as far as I can see. – bolts Jul 07 '21 at 10:31
  • You should try to comment down individual parts of your code and see which one invokes this error. – Ruks Jul 07 '21 at 10:34
  • @Ruks: I have tried that to the point of completely commenting out all code except for the ```include``` statements, and the error was still there. I will try to remove the ```include``` statements one by one. – bolts Jul 07 '21 at 10:39
  • What seems to solve the problem is removing the inclusion of a seemingly innocuous header file that only contains a struct (with no methods defined, so no potentially-ambiguous calls to ```min```), and other ```include``` statements to a range of ```QuantLib``` headers (mostly redundant), ```string```, ```iostream``` and ```vector```. Of course one solution is to take the struct definition and put it directly in my code - for the sake of understanding what is truly causing the error, I will try to remove the ```include``` statements to ```QuantLib``` headers one by one. – bolts Jul 07 '21 at 10:55
  • Very interestingly, commenting out ```include``` statements one by one did not highlight anything in particular - the error was still there regardless. However, I included back the header containing the struct in my code, performed a rebuild, and everything seemingly compiled normally - I wonder if some "loose ends" were stuck in a compilation cache somewhere then? – bolts Jul 07 '21 at 11:40
  • Oof. Check precompiled headers. In principle the kind of error indicates a type error inside a particular TU, so unless precompiled headers are used no possible "loose ends" can possibly be cached. – sehe Jul 07 '21 at 19:57
  • please create a [mcve]. Do you have `windows.h` included? And note that [`using namespace std` is a bad practice](https://stackoverflow.com/q/1452721/995714) and may cause many problems later, especially when you `#include ` – phuclv Jul 11 '21 at 03:53
  • Apologies for the delay - I will try to make a small reproducible example, which at this stage may be just a collection of ```using``` and ```include``` statements. – bolts Jul 13 '21 at 21:18
  • I added an example - please do let me know if it is helpful enough to understand the issue. Thanks again! – bolts Jul 14 '21 at 09:15

0 Answers0