From 44d4957a6f293ee711e11cf57d07f3fb47e60f2a Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 12 Mar 2025 22:59:53 +0100 Subject: [PATCH] memdebug.h: avoid `-Wredundant-decls` with an extra guard MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add an extra guard for the function and variable declarations to avoid redundant redeclaration warnings when including this header multiple times. This can happen in unity builds when including it again after `curl_memory.h`. Fixes: ``` bld/tests/server/CMakeFiles/servers.dir/Unity/unity_0_c.c In file included from lib/mprintf.c:32, from bld/tests/server/CMakeFiles/servers.dir/Unity/unity_0_c.c:7: lib/memdebug.h:52:14: error: redundant redeclaration of ‘curl_dbg_logfile’ [-Werror=redundant-decls] 52 | extern FILE *curl_dbg_logfile; | ^~~~~~~~~~~~~~~~ In file included from tests/server/resolve.c:50, from bld/tests/server/server_bundle.c:7, from bld/tests/server/CMakeFiles/servers.dir/Unity/unity_0_c.c:4: lib/memdebug.h:52:14: note: previous declaration of ‘curl_dbg_logfile’ with type ‘FILE *’ 52 | extern FILE *curl_dbg_logfile; | ^~~~~~~~~~~~~~~~ [...] lib/memdebug.h:110:17: error: redundant redeclaration of ‘curl_dbg_fclose’ [-Werror=redundant-decls] 110 | CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source); | ^~~~~~~~~~~~~~~ lib/memdebug.h:110:17: note: previous declaration of ‘curl_dbg_fclose’ with type ‘int(FILE *, int, const char *)’ 110 | CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source); | ^~~~~~~~~~~~~~~ ``` Ref: https://github.com/curl/curl/actions/runs/13822010778/job/38669360980#step:39:55 Cherry-picked from #15000 Closes #16696 --- lib/memdebug.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/memdebug.h b/lib/memdebug.h index f45d4925f6..acc17a1d56 100644 --- a/lib/memdebug.h +++ b/lib/memdebug.h @@ -49,6 +49,10 @@ #define CURL_MT_LOGFNAME_BUFSIZE 512 +/* Avoid redundant redeclaration warnings with modern compilers, when including + this header multiple times. */ +#ifndef HEADER_CURL_MEMDEBUG_H_EXTERNS +#define HEADER_CURL_MEMDEBUG_H_EXTERNS extern FILE *curl_dbg_logfile; /* memory functions */ @@ -108,6 +112,7 @@ CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode, int line, const char *source); CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source); +#endif /* HEADER_CURL_MEMDEBUG_H_EXTERNS */ #ifndef MEMDEBUG_NODEFINES -- 2.47.3