Skip to content

Commit fb0e694

Browse files
committed
Fix conversion warning in common/cvt
+ constexpr
1 parent fe7e74a commit fb0e694

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

src/common/TimeZoneUtil.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ class TimeZoneUtil
5656
static const ISC_DATE TIME_TZ_BASE_DATE;
5757
static const char GMT_FALLBACK[5]; // "GMT*"
5858

59-
static const USHORT GMT_ZONE = 65535;
60-
static const unsigned MAX_LEN = 32;
61-
static const unsigned MAX_SIZE = MAX_LEN + 1;
59+
static inline constexpr USHORT GMT_ZONE = 65535;
60+
static inline constexpr unsigned MAX_LEN = 32;
61+
static inline constexpr unsigned MAX_SIZE = MAX_LEN + 1;
6262

6363
private:
6464
static InitInstance<PathName> tzDataPath;
@@ -106,7 +106,7 @@ class TimeZoneUtil
106106
static void localTimeStampToUtc(ISC_TIMESTAMP& timeStamp, Callbacks* cb);
107107
static void localTimeStampToUtc(ISC_TIMESTAMP_TZ& timeStampTz);
108108

109-
static const SLONG NO_OFFSET = MAX_SLONG;
109+
static inline constexpr SLONG NO_OFFSET = MAX_SLONG;
110110

111111
static bool decodeTime(const ISC_TIME_TZ& timeTz, bool gmtFallback, SLONG gmtOffset,
112112
struct tm* times, int* fractions = NULL);

src/common/cvt.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ using namespace Firebird;
117117
* less than the number of bits in the type: one bit is for the sign,
118118
* and the other is because we divide by 5, rather than 10. */
119119

120-
const SSHORT SHORT_LIMIT = ((1 << 14) / 5);
121-
const SLONG LONG_LIMIT = ((1L << 30) / 5);
120+
constexpr SSHORT SHORT_LIMIT = ((1 << 14) / 5);
121+
constexpr SLONG LONG_LIMIT = ((1L << 30) / 5);
122122

123123
// NOTE: The syntax for the below line may need modification to ensure
124124
// the result of 1 << 62 is a quad
125125

126126
//#define QUAD_LIMIT ((((SINT64) 1) << 62) / 5)
127-
const SINT64 INT64_LIMIT = ((((SINT64) 1) << 62) / 5);
127+
constexpr SINT64 INT64_LIMIT = ((((SINT64) 1) << 62) / 5);
128128

129129
#define TODAY "TODAY"
130130
#define NOW "NOW"
@@ -201,13 +201,13 @@ class RetValue : public RetPtr
201201

202202
void truncate8() override
203203
{
204-
ULONG mask = 0xFFFFFFFF;
204+
constexpr ULONG mask = 0xFFFFFFFF;
205205
value &= mask;
206206
}
207207

208208
void truncate16() override
209209
{
210-
FB_UINT64 mask = 0xFFFFFFFFFFFFFFFF;
210+
constexpr FB_UINT64 mask = 0xFFFFFFFFFFFFFFFF;
211211
value &= mask;
212212
}
213213

@@ -243,8 +243,8 @@ class RetValue : public RetPtr
243243

244244
} // anonymous namespace
245245

246-
static const double eps_double = 1e-14;
247-
static const double eps_float = 1e-5;
246+
static constexpr double eps_double = 1e-14;
247+
static constexpr double eps_float = 1e-5;
248248

249249

250250
static void validateTimeStamp(const ISC_TIMESTAMP timestamp, const EXPECT_DATETIME expectedType, const dsc* desc,
@@ -459,7 +459,7 @@ static void decimal_float_to_text(const dsc* from, dsc* to, DecimalStatus decSt,
459459
intermediate.dsc_dtype = dtype_text;
460460
intermediate.dsc_ttype() = ttype_ascii;
461461
intermediate.dsc_address = reinterpret_cast<UCHAR*>(temp);
462-
intermediate.dsc_length = strlen(temp);
462+
intermediate.dsc_length = static_cast<USHORT>(strlen(temp));
463463

464464
CVT_move_common(&intermediate, to, 0, cb);
465465
}
@@ -487,7 +487,7 @@ static void int128_to_text(const dsc* from, dsc* to, Callbacks* cb)
487487
intermediate.dsc_dtype = dtype_text;
488488
intermediate.dsc_ttype() = ttype_ascii;
489489
intermediate.dsc_address = reinterpret_cast<UCHAR*>(temp);
490-
intermediate.dsc_length = strlen(temp);
490+
intermediate.dsc_length = static_cast<USHORT>(strlen(temp));
491491

492492
CVT_move_common(&intermediate, to, 0, cb);
493493
}
@@ -710,8 +710,8 @@ void CVT_string_to_datetime(const dsc* desc,
710710
// 0 means missing
711711
// ENGLISH_MONTH for the presence of an English month name
712712
// SPECIAL for a special date verb
713-
const int ENGLISH_MONTH = -1;
714-
const int SPECIAL = -2; // CVC: I see it set, but never tested.
713+
constexpr int ENGLISH_MONTH = -1;
714+
constexpr int SPECIAL = -2; // CVC: I see it set, but never tested.
715715

716716
unsigned int position_year = 0;
717717
unsigned int position_month = 1;
@@ -1384,7 +1384,7 @@ bool CVT_get_boolean(const dsc* desc, ErrorFunction err)
13841384
else if (len == 5 && fb_utils::strnicmp(p, "FALSE", len) == 0)
13851385
return false;
13861386

1387-
// fall into
1387+
[[fallthrough]];
13881388
}
13891389

13901390
default:
@@ -1907,7 +1907,7 @@ void CVT_move_common(const dsc* from, dsc* to, DecimalStatus decSt, Callbacks* c
19071907

19081908
case dtype_varying:
19091909
MOVE_CLEAR(to->dsc_address, to->dsc_length);
1910-
// fall through ...
1910+
[[fallthrough]];
19111911
case dtype_text:
19121912
case dtype_cstring:
19131913
switch (from->dsc_dtype)
@@ -2107,8 +2107,8 @@ void CVT_move_common(const dsc* from, dsc* to, DecimalStatus decSt, Callbacks* c
21072107
}
21082108

21092109
default:
2110-
fb_assert(false); // Fall into ...
2111-
2110+
fb_assert(false);
2111+
[[fallthrough]];
21122112
case dtype_blob:
21132113
CVT_conversion_error(from, cb->err);
21142114
return;
@@ -2344,7 +2344,7 @@ static void datetime_to_text(const dsc* from, dsc* to, Callbacks* cb)
23442344
memset(&times, 0, sizeof(struct tm));
23452345

23462346
int fractions = 0;
2347-
USHORT timezone;
2347+
USHORT timezone = TimeZoneUtil::GMT_ZONE;
23482348

23492349
switch (from->dsc_dtype)
23502350
{
@@ -3198,8 +3198,8 @@ Int128 CVT_get_int128(const dsc* desc, SSHORT scale, DecimalStatus decSt, ErrorF
31983198
Decimal128 tmp;
31993199
double d, eps;
32003200

3201-
static const double I128_MIN_dbl = -1.7014118346046923e+38;
3202-
static const double I128_MAX_dbl = 1.7014118346046921e+38;
3201+
static constexpr double I128_MIN_dbl = -1.7014118346046923e+38;
3202+
static constexpr double I128_MAX_dbl = 1.7014118346046921e+38;
32033203
static const CDecimal128 I128_MIN_dcft("-1.701411834604692317316873037158841E+38", decSt);
32043204
static const CDecimal128 I128_MAX_dcft( "1.701411834604692317316873037158841E+38", decSt);
32053205
static const CDecimal128 DecFlt_05("0.5", decSt);
@@ -3363,7 +3363,7 @@ const UCHAR* CVT_get_bytes(const dsc* desc, unsigned& size)
33633363
}
33643364

33653365
case dtype_cstring:
3366-
size = strlen((const char*) desc->dsc_address);
3366+
size = static_cast<unsigned>(strlen((const char*) desc->dsc_address));
33673367
return desc->dsc_address;
33683368

33693369
default:

0 commit comments

Comments
 (0)