[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] MSVS compilation problem with 100_cents in ternary operator
From: |
Vadim Zeitlin |
Subject: |
Re: [lmi] MSVS compilation problem with 100_cents in ternary operator |
Date: |
Tue, 18 May 2021 14:36:16 +0200 |
On Tue, 18 May 2021 11:22:14 +0000 Greg Chicares <gchicares@sbcglobal.net>
wrote:
GC> On 5/18/21 12:33 AM, Vadim Zeitlin wrote:
GC> >
GC> > I've tried building the latest master with MSVS and it complains about
GC> > using operator _cents in non-constant expression when it's used in the
GC> > following line
GC> >
GC> > return InvariantValues().IsMec ? -100_cents : 100_cents;
GC> >
GC> > of ihs_avsolve.cpp.
GC> >
GC> > I'm not sure if this is a compiler bug or the expression is really
GC> > non-constant (which could be the case if it's only the whole expression
and
GC> > not each of the 2 subexpressions, that counts),
GC>
GC> As you suggested, in commit b88a684a2, I've partially reverted 237cf7245:
GC>
GC> - return InvariantValues().IsMec ? -100_cents : 100_cents;
GC> + static constexpr currency C100 = 100_cents;
GC> + return InvariantValues().IsMec ? -C100 : C100;
Thanks!
GC> In this one isolated instance, I don't mind. But does msvc similarly
GC> dislike the changes that 237cf72453 made in 'loads_test.cpp'? E.g.:
GC>
GC> - loads_.monthly_policy_fee_ [mce_gen_curr] =
std::vector<currency>(length, from_cents(525));
GC> - loads_.annual_policy_fee_ [mce_gen_curr] =
std::vector<currency>(length, from_cents(100));
GC> + loads_.monthly_policy_fee_ [mce_gen_curr] =
std::vector<currency>(length, 525_cents);
GC> + loads_.annual_policy_fee_ [mce_gen_curr] =
std::vector<currency>(length, 100_cents);
GC>
GC> If that's also a problem, then maybe we need a workaround for msvc,
GC> such as:
GC>
GC> #if defined MSVC_MACRO
GC> inline currency operator""_cents(unsigned long long int cents)
GC> #else // !defined MSVC_MACRO
GC> consteval currency operator""_cents(unsigned long long int cents)
GC> #endif
I'm afraid you're right, it indeed gives an error here too (which I didn't
notice because I don't build all tests with MSVS, just a small subset that
I had to debug in the past). I don't use the latest version of the compiler
so I need to update it first, but I'd rather not do this immediately, so
I've added this to my TODO list and will make a patch like above if it
still doesn't work with the latest version.
Thanks again for applying the temporary fix for now,
VZ
pgpJ547XhBflW.pgp
Description: PGP signature