add __attribute__((noreturn)) to suppress a waring
I found the following warning with Fedora 14 / gcc 4.5.1.
----
pg_backup_archiver.c: In function ‘_discoverArchiveFormat’:
pg_backup_archiver.c:1736:11: warning: ‘fh’ may be used uninitialized
in this function
----
To suppress it, I'm thinking to add noreturn to die_horribly().
Any objections? Another solution might be adding a dummy assignment
after calls of die_horribly().
--
Itagaki Takahiro
Attachments:
noreturn.diffapplication/octet-stream; name=noreturn.diffDownload
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index d001ff4..97aaa7d 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -119,7 +119,7 @@ static int _discoverArchiveFormat(ArchiveHandle *AH);
static void dump_lo_buf(ArchiveHandle *AH);
static void _write_msg(const char *modulename, const char *fmt, va_list ap);
-static void _die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_list ap);
+static void _die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_list ap) __attribute__((noreturn));
static void dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim);
static void SetOutput(ArchiveHandle *AH, char *filename, int compression);
diff --git a/src/bin/pg_dump/pg_backup_archiver.h b/src/bin/pg_dump/pg_backup_archiver.h
index 8d3bbe0..8cb82a9 100644
--- a/src/bin/pg_dump/pg_backup_archiver.h
+++ b/src/bin/pg_dump/pg_backup_archiver.h
@@ -329,7 +329,7 @@ typedef struct _tocEntry
/* Used everywhere */
extern const char *progname;
-extern void die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(printf, 3, 4)));
+extern void die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(printf, 3, 4))) __attribute__((noreturn));
extern void warn_or_die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(printf, 3, 4)));
extern void write_msg(const char *modulename, const char *fmt,...) __attribute__((format(printf, 2, 3)));
On 24.01.2011 03:42, Itagaki Takahiro wrote:
I found the following warning with Fedora 14 / gcc 4.5.1.
----
pg_backup_archiver.c: In function ‘_discoverArchiveFormat’:
pg_backup_archiver.c:1736:11: warning: ‘fh’ may be used uninitialized
in this function
----
To suppress it, I'm thinking to add noreturn to die_horribly().
Any objections? Another solution might be adding a dummy assignment
after calls of die_horribly().
I added a dummy assignment, that's how we've handled this before in
pg_dump. I guess we could use noreturn, we already use it in pg_re_throw
function. But we also have a dummy exit(1) call in the PG_RE_THROW macro
for non-gcc compilers, so we might need to do that here too.
Thanks!
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com
Heikki Linnakangas <heikki.linnakangas@enterprisedb.com> writes:
On 24.01.2011 03:42, Itagaki Takahiro wrote:
To suppress it, I'm thinking to add noreturn to die_horribly().
Any objections? Another solution might be adding a dummy assignment
after calls of die_horribly().
I added a dummy assignment, that's how we've handled this before in
pg_dump.
We generally do *not* want to depend on noreturn, because it will not
suppress similar warnings in non-gcc compilers. Just add a dummy
initialization, or reorganize the code to avoid the problem.
regards, tom lane