[PATCH] Fix compiler warnings by using designated initializers
Use C99 designated initializers (.type = T_ErrorSaveContext) instead of the
standard initializer {T_ErrorSaveContext} when initializing ErrorSaveContext.
This avoids missing-field-initializers compiler warnings for the remaining fields of
the struct (e.g. error_occurred).
Also fix a sign comparison warning in pg_dependencies_out() by changing
the loop counter from int to uint32 to match dependencies->ndeps.
Signed-off-by: Zakariyah Ali <zakariyahali100@gmail.com>
---
src/backend/access/transam/xlogrecovery.c | 2 +-
src/backend/commands/copy.c | 2 +-
src/backend/commands/tablecmds.c | 2 +-
src/backend/parser/parse_node.c | 2 +-
src/backend/parser/scan.l | 4 +--
src/backend/statistics/mcv.c | 2 +-
src/backend/statistics/stat_utils.c | 2 +-
src/backend/utils/adt/date.c | 4 +--
src/backend/utils/adt/formatting.c | 2 +-
src/backend/utils/adt/jsonfuncs.c | 2 +-
src/backend/utils/adt/jsonpath_exec.c | 34 +++++++++++------------
src/backend/utils/adt/misc.c | 4 +--
src/backend/utils/adt/pg_dependencies.c | 4 +--
src/backend/utils/adt/pg_ndistinct.c | 2 +-
src/backend/utils/adt/regproc.c | 22 +++++++--------
src/backend/utils/adt/timestamp.c | 2 +-
src/backend/utils/adt/xml.c | 6 ++--
src/backend/utils/cache/ts_cache.c | 4 +--
18 files changed, 51 insertions(+), 51 deletions(-)
diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index 73b78a83fa7..49196a94a8d 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -4833,7 +4833,7 @@ check_recovery_target_lsn(char **newval, void **extra, GucSource source)
{
XLogRecPtr lsn;
XLogRecPtr *myextra;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
lsn = pg_lsn_in_safe(*newval, (Node *) &escontext);
if (escontext.error_occurred)
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 003b70852bb..4bc4416a58a 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -440,7 +440,7 @@ defGetCopyHeaderOption(DefElem *def, bool is_from)
}
else
{
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
/* Check if the header is a valid integer */
ival = pg_strtoint32_safe(sval, (Node *) &escontext);
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index a1845240a98..d91dabf80aa 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -7640,7 +7640,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
ExprState *exprState;
Datum missingval;
bool missingIsNull;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
/* Evaluate the default expression with soft errors */
estate = CreateExecutorState();
diff --git a/src/backend/parser/parse_node.c b/src/backend/parser/parse_node.c
index dacd851cffd..bcb43a9041d 100644
--- a/src/backend/parser/parse_node.c
+++ b/src/backend/parser/parse_node.c
@@ -381,7 +381,7 @@ make_const(ParseState *pstate, A_Const *aconst)
{
/* could be an oversize integer as well as a float ... */
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
int64 val64;
val64 = pg_strtoint64_safe(aconst->val.fval.fval, (Node *) &escontext);
diff --git a/src/backend/parser/scan.l b/src/backend/parser/scan.l
index ee6c34cc14b..13e34794e4f 100644
--- a/src/backend/parser/scan.l
+++ b/src/backend/parser/scan.l
@@ -976,7 +976,7 @@ other .
}
{param} {
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
int32 val;
SET_YYLLOC();
@@ -1343,7 +1343,7 @@ litbufdup(core_yyscan_t yyscanner)
static int
process_integer_literal(const char *token, YYSTYPE *lval, int base)
{
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
int32 val;
val = pg_strtoint32_safe(token, (Node *) &escontext);
diff --git a/src/backend/statistics/mcv.c b/src/backend/statistics/mcv.c
index 0b7da605a4c..70b09ebb9b2 100644
--- a/src/backend/statistics/mcv.c
+++ b/src/backend/statistics/mcv.c
@@ -2264,7 +2264,7 @@ statext_mcv_import(int elevel, int numattrs,
else
{
char *s = TextDatumGetCString(mcv_elems[index]);
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
if (!InputFunctionCallSafe(&finfo, s, ioparam, atttypmods[j],
(Node *) &escontext, &item->values[j]))
diff --git a/src/backend/statistics/stat_utils.c b/src/backend/statistics/stat_utils.c
index a673e3c704b..a1220b8b60a 100644
--- a/src/backend/statistics/stat_utils.c
+++ b/src/backend/statistics/stat_utils.c
@@ -572,7 +572,7 @@ statatt_build_stavalues(const char *staname, FmgrInfo *array_in, Datum d, Oid ty
LOCAL_FCINFO(fcinfo, 8);
char *s;
Datum result;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
escontext.details_wanted = true;
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c
index 7f746dd84c9..4948936ba52 100644
--- a/src/backend/utils/adt/date.c
+++ b/src/backend/utils/adt/date.c
@@ -764,7 +764,7 @@ int32
date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2)
{
Timestamp dt1;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
dt1 = date2timestamp_safe(dateVal, (Node *) &escontext);
if (escontext.error_occurred)
@@ -845,7 +845,7 @@ int32
date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2)
{
TimestampTz dt1;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
dt1 = date2timestamptz_safe(dateVal, (Node *) &escontext);
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index d52d71b0a8c..a8cbab84dfd 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -6343,7 +6343,7 @@ numeric_to_char(PG_FUNCTION_ARGS)
if (IS_ROMAN(&Num))
{
int32 intvalue;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
/* Round and convert to int */
intvalue = numeric_int4_safe(value, (Node *) &escontext);
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c
index 97cc3d60340..2ad0270422b 100644
--- a/src/backend/utils/adt/jsonfuncs.c
+++ b/src/backend/utils/adt/jsonfuncs.c
@@ -2476,7 +2476,7 @@ jsonb_populate_record(PG_FUNCTION_ARGS)
Datum
jsonb_populate_record_valid(PG_FUNCTION_ARGS)
{
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
(void) populate_record_worker(fcinfo, "jsonb_populate_record",
false, true, (Node *) &escontext);
diff --git a/src/backend/utils/adt/jsonpath_exec.c b/src/backend/utils/adt/jsonpath_exec.c
index 6cc2acb4254..d8d6b5ffda3 100644
--- a/src/backend/utils/adt/jsonpath_exec.c
+++ b/src/backend/utils/adt/jsonpath_exec.c
@@ -1181,7 +1181,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
char *tmp = DatumGetCString(DirectFunctionCall1(numeric_out,
NumericGetDatum(jb->val.numeric)));
double val;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
val = float8in_internal(tmp,
NULL,
@@ -1207,7 +1207,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
double val;
char *tmp = pnstrdup(jb->val.string.val,
jb->val.string.len);
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
val = float8in_internal(tmp,
NULL,
@@ -1296,7 +1296,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (jb->type == jbvNumeric)
{
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
int64 val;
val = numeric_int8_safe(jb->val.numeric,
@@ -1318,7 +1318,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
/* cast string as bigint */
char *tmp = pnstrdup(jb->val.string.val,
jb->val.string.len);
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
bool noerr;
noerr = DirectInputFunctionCallSafe(int8in, tmp,
@@ -1370,7 +1370,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
bool noerr;
char *tmp = DatumGetCString(DirectFunctionCall1(numeric_out,
NumericGetDatum(jb->val.numeric)));
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
noerr = DirectInputFunctionCallSafe(int4in, tmp,
InvalidOid, -1,
@@ -1449,7 +1449,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
/* cast string as number */
Datum datum;
bool noerr;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
numstr = pnstrdup(jb->val.string.val, jb->val.string.len);
@@ -1497,7 +1497,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
Datum datums[2];
char pstr[12]; /* sign, 10 digits and '\0' */
char sstr[12]; /* sign, 10 digits and '\0' */
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
jspGetLeftArg(jsp, &elem);
if (elem.type != jpiNumeric)
@@ -1575,7 +1575,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (jb->type == jbvNumeric)
{
int32 val;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
val = numeric_int4_safe(jb->val.numeric,
(Node *) &escontext);
@@ -1595,7 +1595,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
/* cast string as integer */
char *tmp = pnstrdup(jb->val.string.val,
jb->val.string.len);
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
bool noerr;
noerr = DirectInputFunctionCallSafe(int4in, tmp,
@@ -2238,7 +2238,7 @@ executeBinaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
}
else
{
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
res = func(lval->val.numeric, rval->val.numeric, (Node *) &escontext);
@@ -2482,7 +2482,7 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
text *template;
char *template_str;
int template_len;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
jspGetArg(jsp, &elem);
@@ -2540,7 +2540,7 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (jsp->type != jpiDatetime && jsp->type != jpiDate &&
jsp->content.arg)
{
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
jspGetArg(jsp, &elem);
@@ -2560,7 +2560,7 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
/* loop until datetime format fits */
for (i = 0; i < lengthof(fmt_str); i++)
{
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
if (!fmt_txt[i])
{
@@ -2771,7 +2771,7 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (time_precision != -1)
{
Timestamp result;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
/* Get a warning when precision is reduced */
time_precision = anytimestamp_typmod_check(false,
@@ -2852,7 +2852,7 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (time_precision != -1)
{
Timestamp result;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
/* Get a warning when precision is reduced */
time_precision = anytimestamp_typmod_check(true,
@@ -3018,7 +3018,7 @@ executeStringInternalMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
{
char *from_str;
int32 n;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
jspGetLeftArg(jsp, &elem);
if (elem.type != jpiString)
@@ -3740,7 +3740,7 @@ getArrayIndex(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
JsonValueList found;
JsonPathExecResult res;
Datum numeric_index;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
JsonValueListInit(&found);
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index c033e68ba15..1e30155942c 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -670,7 +670,7 @@ pg_input_is_valid(PG_FUNCTION_ARGS)
{
text *txt = PG_GETARG_TEXT_PP(0);
text *typname = PG_GETARG_TEXT_PP(1);
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
PG_RETURN_BOOL(pg_input_is_valid_common(fcinfo, txt, typname,
&escontext));
@@ -690,7 +690,7 @@ pg_input_error_info(PG_FUNCTION_ARGS)
{
text *txt = PG_GETARG_TEXT_PP(0);
text *typname = PG_GETARG_TEXT_PP(1);
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
TupleDesc tupdesc;
Datum values[4];
bool isnull[4];
diff --git a/src/backend/utils/adt/pg_dependencies.c b/src/backend/utils/adt/pg_dependencies.c
index 7441004909f..eb5c1a8366b 100644
--- a/src/backend/utils/adt/pg_dependencies.c
+++ b/src/backend/utils/adt/pg_dependencies.c
@@ -480,7 +480,7 @@ dependencies_scalar(void *state, char *token, JsonTokenType tokentype)
{
DependenciesParseState *parse = state;
AttrNumber attnum;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
switch (parse->state)
{
@@ -820,7 +820,7 @@ pg_dependencies_out(PG_FUNCTION_ARGS)
initStringInfo(&str);
appendStringInfoChar(&str, '[');
- for (int i = 0; i < dependencies->ndeps; i++)
+ for (uint32 i = 0; i < dependencies->ndeps; i++)
{
MVDependency *dependency = dependencies->deps[i];
diff --git a/src/backend/utils/adt/pg_ndistinct.c b/src/backend/utils/adt/pg_ndistinct.c
index 8d854012d6e..03ccd227c38 100644
--- a/src/backend/utils/adt/pg_ndistinct.c
+++ b/src/backend/utils/adt/pg_ndistinct.c
@@ -421,7 +421,7 @@ ndistinct_scalar(void *state, char *token, JsonTokenType tokentype)
{
NDistinctParseState *parse = state;
AttrNumber attnum;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
switch (parse->state)
{
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index 64f293f4e98..214c451a0ff 100644
--- a/src/backend/utils/adt/regproc.c
+++ b/src/backend/utils/adt/regproc.c
@@ -122,7 +122,7 @@ to_regproc(PG_FUNCTION_ARGS)
{
char *pro_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
Datum result;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
if (!DirectInputFunctionCallSafe(regprocin, pro_name,
InvalidOid, -1,
@@ -285,7 +285,7 @@ to_regprocedure(PG_FUNCTION_ARGS)
{
char *pro_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
Datum result;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
if (!DirectInputFunctionCallSafe(regprocedurein, pro_name,
InvalidOid, -1,
@@ -535,7 +535,7 @@ to_regoper(PG_FUNCTION_ARGS)
{
char *opr_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
Datum result;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
if (!DirectInputFunctionCallSafe(regoperin, opr_name,
InvalidOid, -1,
@@ -703,7 +703,7 @@ to_regoperator(PG_FUNCTION_ARGS)
{
char *opr_name_or_oid = text_to_cstring(PG_GETARG_TEXT_PP(0));
Datum result;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
if (!DirectInputFunctionCallSafe(regoperatorin, opr_name_or_oid,
InvalidOid, -1,
@@ -934,7 +934,7 @@ to_regclass(PG_FUNCTION_ARGS)
{
char *class_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
Datum result;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
if (!DirectInputFunctionCallSafe(regclassin, class_name,
InvalidOid, -1,
@@ -1077,7 +1077,7 @@ to_regcollation(PG_FUNCTION_ARGS)
{
char *collation_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
Datum result;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
if (!DirectInputFunctionCallSafe(regcollationin, collation_name,
InvalidOid, -1,
@@ -1218,7 +1218,7 @@ to_regtype(PG_FUNCTION_ARGS)
{
char *typ_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
Datum result;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
if (!DirectInputFunctionCallSafe(regtypein, typ_name,
InvalidOid, -1,
@@ -1239,7 +1239,7 @@ to_regtypemod(PG_FUNCTION_ARGS)
char *typ_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
Oid typid;
int32 typmod;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
/* We rely on parseTypeString to parse the input. */
if (!parseTypeString(typ_name, &typid, &typmod, (Node *) &escontext))
@@ -1592,7 +1592,7 @@ to_regrole(PG_FUNCTION_ARGS)
{
char *role_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
Datum result;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
if (!DirectInputFunctionCallSafe(regrolein, role_name,
InvalidOid, -1,
@@ -1709,7 +1709,7 @@ to_regnamespace(PG_FUNCTION_ARGS)
{
char *nsp_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
Datum result;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
if (!DirectInputFunctionCallSafe(regnamespacein, nsp_name,
InvalidOid, -1,
@@ -1826,7 +1826,7 @@ to_regdatabase(PG_FUNCTION_ARGS)
{
char *db_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
Datum result;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
if (!DirectInputFunctionCallSafe(regdatabasein, db_name,
InvalidOid, -1,
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index a20e7ea1d11..5bcf295a2e9 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -2375,7 +2375,7 @@ int32
timestamp_cmp_timestamptz_internal(Timestamp timestampVal, TimestampTz dt2)
{
TimestampTz dt1;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
dt1 = timestamp2timestamptz_safe(timestampVal, (Node *) &escontext);
if (escontext.error_occurred)
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index 2c7f778cfdb..4d530ae5f27 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -684,7 +684,7 @@ xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)
xmlNodePtr content_nodes;
volatile xmlBufferPtr buf = NULL;
volatile xmlSaveCtxtPtr ctxt = NULL;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
PgXmlErrorContext *volatile xmlerrcxt = NULL;
#endif
@@ -1173,7 +1173,7 @@ xml_is_document(xmltype *arg)
{
#ifdef USE_LIBXML
xmlDocPtr doc;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
/*
* We'll report "true" if no soft error is reported by xml_parse().
@@ -4640,7 +4640,7 @@ static bool
wellformed_xml(text *data, XmlOptionType xmloption_arg)
{
xmlDocPtr doc;
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
/*
* We'll report "true" if no soft error is reported by xml_parse().
diff --git a/src/backend/utils/cache/ts_cache.c b/src/backend/utils/cache/ts_cache.c
index 9e29f1386b0..1e9e381a2ca 100644
--- a/src/backend/utils/cache/ts_cache.c
+++ b/src/backend/utils/cache/ts_cache.c
@@ -587,7 +587,7 @@ getTSCurrentConfig(bool emitError)
}
else
{
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
namelist = stringToQualifiedNameList(TSCurrentConfig,
(Node *) &escontext);
@@ -611,7 +611,7 @@ check_default_text_search_config(char **newval, void **extra, GucSource source)
*/
if (IsTransactionState() && MyDatabaseId != InvalidOid)
{
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
List *namelist;
Oid cfgId;
HeapTuple tuple;
--
2.43.0
Zakariyah Ali <zakariyahali100@gmail.com> writes:
Use C99 designated initializers (.type = T_ErrorSaveContext) instead of the
standard initializer {T_ErrorSaveContext} when initializing ErrorSaveContext.
This avoids missing-field-initializers compiler warnings for the remaining fields of
the struct (e.g. error_occurred).
What compiler produces such warnings? I'm not really eager to make
invasive, more-typing-required changes like this, especially when
it's not obvious that the modified code is any more correct.
Also fix a sign comparison warning in pg_dependencies_out() by changing
the loop counter from int to uint32 to match dependencies->ndeps.
Same question --- I see no such complaints in our buildfarm.
regards, tom lane
On 04.06.26 18:36, Tom Lane wrote:
Zakariyah Ali <zakariyahali100@gmail.com> writes:
Use C99 designated initializers (.type = T_ErrorSaveContext) instead of the
standard initializer {T_ErrorSaveContext} when initializing ErrorSaveContext.
This avoids missing-field-initializers compiler warnings for the remaining fields of
the struct (e.g. error_occurred).What compiler produces such warnings? I'm not really eager to make
invasive, more-typing-required changes like this, especially when
it's not obvious that the modified code is any more correct.
I think -Wmissing-field-initializers was meant here.
It looks like all of the changes are of the form
- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
Maybe we could do this more elegantly and safer with a non-pointer
variant of makeNode/newNode.
Like
#define initNode(_type_) ((_type_){.type = T_##_type_})
ErrorSaveContext escontext = initNode(ErrorSaveContext);
(Or something else instead of "init".)
Peter Eisentraut <peter@eisentraut.org> writes:
It looks like all of the changes are of the form
- ErrorSaveContext escontext = {T_ErrorSaveContext}; + ErrorSaveContext escontext = {.type = T_ErrorSaveContext};
Right, that was my understanding too.
Maybe we could do this more elegantly and safer with a non-pointer
variant of makeNode/newNode.
Like
#define initNode(_type_) ((_type_){.type = T_##_type_})
ErrorSaveContext escontext = initNode(ErrorSaveContext);
Hmm, that would reduce the risk of writing the wrong T_Foo constant in
this context, but it doesn't seem to me that that risk is high as-is.
Macro wrapper or not, I'm still unclear on why we should think that
this change improves anything. It seems 100.00% arbitrary that this
particular compiler switch produces a warning about the first usage
and not the second, or that some other compiler wouldn't produce a
warning about the second usage. I do see that the gcc manual
documents -Wmissing-field-initializers as behaving this way, but
that doesn't make it any less random.
So my answer to this is "don't use -Wmissing-field-initializers".
The only argument I can see in favor of trying to make our build
clean with that is if we were going to try to be clean with
-Wextra in general. But a quick check says that -Wextra still
produces thousands of lines of pedantry.
In any case, I'd want to see an explicit project decision to make
cleanliness against any new warning switch be a supported thing.
That would probably mean turning it on by default, not just
occasionally accepting drive-by patches about it.
regards, tom lane
Hi Tom, Peter,
The warnings for the `ErrorSaveContext` and the `pg_dependencies_out()` loop counter were observed with GCC using the `-Wmissing-field-initializers` and `-Wsign-compare` flags.
However, I completely understand the concern that these warnings are not part of PostgreSQL's currently supported warning set. I agree that making code changes (like switching to designated initializers or changing loop types) just to satisfy these non-default flags isn't the right approach without a project-wide consensus to enforce them.
Given that, I will drop this patch. Thank you both for your time, the reviews, and the insights into how the project handles compiler warnings!
Best regards,
Zakariyah