Skip to content

Commit 89b30c3

Browse files
committed
ogr/ogrsf_frmts/generic: enable -Wdouble-promotion
1 parent 0823069 commit 89b30c3

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

ogr/ogrsf_frmts/generic/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ add_library(
4444
ograrrowarrayhelper.cpp)
4545
gdal_standard_includes(ogrsf_generic)
4646
add_dependencies(ogrsf_generic generate_gdal_version_h)
47-
target_compile_options(ogrsf_generic PRIVATE ${GDAL_CXX_WARNING_FLAGS} ${WFLAG_OLD_STYLE_CAST} ${WFLAG_EFFCXX})
47+
target_compile_options(ogrsf_generic PRIVATE ${GDAL_CXX_WARNING_FLAGS} ${WFLAG_OLD_STYLE_CAST} ${WFLAG_EFFCXX} ${WFLAG_DOUBLE_PROMOTION})
4848
target_sources(${GDAL_LIB_TARGET_NAME} PRIVATE $<TARGET_OBJECTS:ogrsf_generic>)
4949
set_property(TARGET ogrsf_generic PROPERTY POSITION_INDEPENDENT_CODE ${GDAL_OBJECT_LIBRARIES_POSITION_INDEPENDENT_CODE})
5050

ogr/ogrsf_frmts/generic/ograrrowarrayhelper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class CPL_DLL OGRArrowArrayHelper
180180
brokenDown.tm_sec = static_cast<int>(ogrField.Date.Second);
181181
auto nVal =
182182
CPLYMDHMSToUnixTime(&brokenDown) * 1000 +
183-
(static_cast<int>(ogrField.Date.Second * 1000 + 0.5) % 1000);
183+
(static_cast<int>(ogrField.Date.Second * 1000 + 0.5f) % 1000);
184184
if (nFieldTZFlag >= OGR_TZFLAG_MIXED_TZ &&
185185
ogrField.Date.TZFlag > OGR_TZFLAG_MIXED_TZ)
186186
{

ogr/ogrsf_frmts/generic/ogrlayerarrow.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,7 @@ static bool FillTimeArray(struct ArrowArray *psChild,
17381738
panValues[iFeat] =
17391739
psRawField->Date.Hour * 3600000 +
17401740
psRawField->Date.Minute * 60000 +
1741-
static_cast<int>(psRawField->Date.Second * 1000 + 0.5);
1741+
static_cast<int>(psRawField->Date.Second * 1000 + 0.5f);
17421742
}
17431743
else if (bIsNullable)
17441744
{
@@ -1795,7 +1795,8 @@ FillDateTimeArray(struct ArrowArray *psChild,
17951795
brokenDown.tm_sec = static_cast<int>(psRawField->Date.Second);
17961796
auto nVal =
17971797
CPLYMDHMSToUnixTime(&brokenDown) * 1000 +
1798-
(static_cast<int>(psRawField->Date.Second * 1000 + 0.5) % 1000);
1798+
(static_cast<int>(psRawField->Date.Second * 1000 + 0.5f) %
1799+
1000);
17991800
if (nFieldTZFlag >= OGR_TZFLAG_MIXED_TZ &&
18001801
psRawField->Date.TZFlag > OGR_TZFLAG_MIXED_TZ)
18011802
{
@@ -3882,7 +3883,7 @@ inline static void FillFieldListFromHalfFloat(
38823883
const auto nFloat16AsUInt32 = CPLHalfToFloat(paValues[i]);
38833884
float f;
38843885
memcpy(&f, &nFloat16AsUInt32, sizeof(f));
3885-
aValues.push_back(f);
3886+
aValues.push_back(static_cast<double>(f));
38863887
}
38873888
oFeature.SetField(iOGRFieldIdx, static_cast<int>(aValues.size()),
38883889
aValues.data());
@@ -4105,9 +4106,9 @@ static void AddToArray(CPLJSONArray &oArray, const struct ArrowSchema *schema,
41054106
else if (IsInt64(schema->format))
41064107
oArray.Add(static_cast<GIntBig>(GetValue<int64_t>(array, nIdx)));
41074108
else if (IsFloat16(schema->format))
4108-
oArray.Add(GetValueFloat16(array, nIdx));
4109+
oArray.Add(static_cast<double>(GetValueFloat16(array, nIdx)));
41094110
else if (IsFloat32(schema->format))
4110-
oArray.Add(GetValue<float>(array, nIdx));
4111+
oArray.Add(static_cast<double>(GetValue<float>(array, nIdx)));
41114112
else if (IsFloat64(schema->format))
41124113
oArray.Add(GetValue<double>(array, nIdx));
41134114
else if (IsString(schema->format))
@@ -4229,9 +4230,9 @@ static void AddToDict(CPLJSONObject &oDict, const std::string &osKey,
42294230
else if (IsInt64(schema->format))
42304231
oDict.Add(osKey, static_cast<GIntBig>(GetValue<int64_t>(array, nIdx)));
42314232
else if (IsFloat16(schema->format))
4232-
oDict.Add(osKey, GetValueFloat16(array, nIdx));
4233+
oDict.Add(osKey, static_cast<double>(GetValueFloat16(array, nIdx)));
42334234
else if (IsFloat32(schema->format))
4234-
oDict.Add(osKey, GetValue<float>(array, nIdx));
4235+
oDict.Add(osKey, static_cast<double>(GetValue<float>(array, nIdx)));
42354236
else if (IsFloat64(schema->format))
42364237
oDict.Add(osKey, GetValue<double>(array, nIdx));
42374238
else if (IsString(schema->format))
@@ -4400,8 +4401,8 @@ static bool SetFieldForOtherFormats(OGRFeature &oFeature,
44004401
{
44014402
oFeature.SetField(
44024403
iOGRFieldIndex,
4403-
GetValueFloat16(array, nOffsettedIndex -
4404-
static_cast<size_t>(array->offset)));
4404+
static_cast<double>(GetValueFloat16(
4405+
array, nOffsettedIndex - static_cast<size_t>(array->offset))));
44054406
}
44064407

44074408
else if (IsFixedWidthBinary(format))
@@ -4596,8 +4597,8 @@ static bool SetFieldForOtherFormats(OGRFeature &oFeature,
45964597
std::vector<double> aValues;
45974598
for (int i = 0; i < nItems; ++i)
45984599
{
4599-
aValues.push_back(
4600-
GetValueFloat16(childArray, nOffsettedIndex * nItems + i));
4600+
aValues.push_back(static_cast<double>(
4601+
GetValueFloat16(childArray, nOffsettedIndex * nItems + i)));
46014602
}
46024603
oFeature.SetField(iOGRFieldIndex, static_cast<int>(aValues.size()),
46034604
aValues.data());
@@ -5128,9 +5129,10 @@ static size_t FillValidityArrayFromAttrQuery(
51285129
}
51295130
else if (IsFloat32(format))
51305131
{
5131-
oFeature.SetField(iOGRFieldIndex,
5132-
static_cast<const float *>(
5133-
psArray->buffers[1])[nOffsettedIndex]);
5132+
oFeature.SetField(
5133+
iOGRFieldIndex,
5134+
static_cast<double>(static_cast<const float *>(
5135+
psArray->buffers[1])[nOffsettedIndex]));
51345136
}
51355137
else if (IsFloat64(format))
51365138
{
@@ -7377,7 +7379,7 @@ static bool FillFeature(OGRLayer *poLayer, const struct ArrowSchema *schema,
73777379
}
73787380
else if (IsFloat32(format))
73797381
{
7380-
FillField<float>(array, iOGRFieldIdx, iFeature, oFeature);
7382+
FillField<float, double>(array, iOGRFieldIdx, iFeature, oFeature);
73817383
return true;
73827384
}
73837385
else if (IsFloat64(format))

0 commit comments

Comments
 (0)