I have some class that can receive things using an overloaded
<< operator, and also accept some settings - conveniently
applied by methods returning *this
so this can be chained.
However, on Microsoft Visual C++ (latest) with /std:c++latest the warning C4866 (compiler may not enforce left-to-right evaluation) is suddenly raised. Any idea why and how to prevent this?
The argument (here to constructor sv_holder must be some more complex type - it works without warnings for pod type).
#include <iostream>
#include <string_view>
class sv_holder
{
public:
sv_holder(std::string_view v) : m_sv(v) {}
std::string_view m_sv;
};
class C
{
public:
C() {}
C &accept(const sv_holder &) { return *this; }
template <typename T> C &operator<<(const T &t)
{
std::cout << t;
return *this;
}
};
void fail_function()
{
C c;
c.accept(sv_holder(__FILE__)) << "stream test";
}