Erroneous -Werror=missing-braces on old GCC

Started by Richard Guoabout 2 years ago4 messages
#1Richard Guo
guofenglinux@gmail.com
1 attachment(s)

I came across the 'missing braces' warning again when building master
(0a93f803f4) on old GCC (4.8.5).

blkreftable.c: In function ‘BlockRefTableSetLimitBlock’:
blkreftable.c:268:2: warning: missing braces around initializer
[-Wmissing-braces]
BlockRefTableKey key = {0}; /* make sure any padding is zero */
^

This has popped up a few times in the past, and it seems to be GCC bug
53119. We previously used the {{...}} approach to suppress it. Should
we do the same here, like attached?

FWIW, in the same file we initialize BlockRefTableSerializedEntry
variables also with {{0}}.

Thanks
Richard

Attachments:

v1-0001-Fix-erroneous-Werror-missing-braces-on-old-GCC.patchapplication/octet-stream; name=v1-0001-Fix-erroneous-Werror-missing-braces-on-old-GCC.patchDownload
From b4510202e7b79b38873dcd6daf664ed3849acc03 Mon Sep 17 00:00:00 2001
From: Richard Guo <guofenglinux@gmail.com>
Date: Mon, 25 Dec 2023 10:25:48 +0800
Subject: [PATCH v1] Fix erroneous -Werror=missing-braces on old GCC

---
 src/common/blkreftable.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/common/blkreftable.c b/src/common/blkreftable.c
index d0ecaa05ef..ab70ebc877 100644
--- a/src/common/blkreftable.c
+++ b/src/common/blkreftable.c
@@ -265,7 +265,7 @@ BlockRefTableSetLimitBlock(BlockRefTable *brtab,
 						   BlockNumber limit_block)
 {
 	BlockRefTableEntry *brtentry;
-	BlockRefTableKey key = {0}; /* make sure any padding is zero */
+	BlockRefTableKey key = {{0}}; /* make sure any padding is zero */
 	bool		found;
 
 	memcpy(&key.rlocator, rlocator, sizeof(RelFileLocator));
@@ -300,7 +300,7 @@ BlockRefTableMarkBlockModified(BlockRefTable *brtab,
 							   BlockNumber blknum)
 {
 	BlockRefTableEntry *brtentry;
-	BlockRefTableKey key = {0}; /* make sure any padding is zero */
+	BlockRefTableKey key = {{0}}; /* make sure any padding is zero */
 	bool		found;
 #ifndef FRONTEND
 	MemoryContext oldcontext = MemoryContextSwitchTo(brtab->mcxt);
@@ -340,7 +340,7 @@ BlockRefTableEntry *
 BlockRefTableGetEntry(BlockRefTable *brtab, const RelFileLocator *rlocator,
 					  ForkNumber forknum, BlockNumber *limit_block)
 {
-	BlockRefTableKey key = {0}; /* make sure any padding is zero */
+	BlockRefTableKey key = {{0}}; /* make sure any padding is zero */
 	BlockRefTableEntry *entry;
 
 	Assert(limit_block != NULL);
@@ -517,7 +517,7 @@ WriteBlockRefTable(BlockRefTable *brtab,
 		for (i = 0; i < brtab->hash->members; ++i)
 		{
 			BlockRefTableSerializedEntry *sentry = &sdata[i];
-			BlockRefTableKey key = {0}; /* make sure any padding is zero */
+			BlockRefTableKey key = {{0}}; /* make sure any padding is zero */
 			unsigned	j;
 
 			/* Write the serialized entry itself. */
-- 
2.31.0

#2Japin Li
japinli@hotmail.com
In reply to: Richard Guo (#1)
Re: Erroneous -Werror=missing-braces on old GCC

On Mon, 25 Dec 2023 at 10:42, Richard Guo <guofenglinux@gmail.com> wrote:

I came across the 'missing braces' warning again when building master
(0a93f803f4) on old GCC (4.8.5).

blkreftable.c: In function ‘BlockRefTableSetLimitBlock’:
blkreftable.c:268:2: warning: missing braces around initializer
[-Wmissing-braces]
BlockRefTableKey key = {0}; /* make sure any padding is zero */
^

I doubt if `key = {0}` equals `key = {{0}}`, since the second only
initialize the first field in `key`, it may depend on compiler to
initialize other fields (include padding).

This has popped up a few times in the past, and it seems to be GCC bug
53119. We previously used the {{...}} approach to suppress it. Should
we do the same here, like attached?

FWIW, in the same file we initialize BlockRefTableSerializedEntry
variables also with {{0}}.

Thanks
Richard

--
Regrads,
Japin Li
ChengDu WenWu Information Technology Co., Ltd.

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Richard Guo (#1)
Re: Erroneous -Werror=missing-braces on old GCC

Richard Guo <guofenglinux@gmail.com> writes:

I came across the 'missing braces' warning again when building master
(0a93f803f4) on old GCC (4.8.5).

On the one hand, it's probably pointless to worry about buggy
warnings from ancient compilers ...

This has popped up a few times in the past, and it seems to be GCC bug
53119. We previously used the {{...}} approach to suppress it. Should
we do the same here, like attached?
FWIW, in the same file we initialize BlockRefTableSerializedEntry
variables also with {{0}}.

... but there is a lot to be said for maintaining stylistic consistency.
Given that we're doing it this way elsewhere, we should do it in these
spots too.

regards, tom lane

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#3)
Re: Erroneous -Werror=missing-braces on old GCC

I wrote:

Richard Guo <guofenglinux@gmail.com> writes:

I came across the 'missing braces' warning again when building master
(0a93f803f4) on old GCC (4.8.5).

On the one hand, it's probably pointless to worry about buggy
warnings from ancient compilers ...

Actually, after checking the buildfarm, I see that

arowana
ayu
batfish
boa
buri
demoiselle
dhole
dragonet
idiacanthus
lapwing
mantid
petalura
rhinoceros
shelduck
siskin
tanager
topminnow
xenodermus

are all bitching about this (with a couple different spellings
of the warning). So this is absolutely something to fix, and
I'm rather surprised that nobody noticed it during the development
of 174c48050.

regards, tom lane