Skip to content

Commit c3b92d4

Browse files
committed
Merge branch 'jk/unused-parameters' into jc/maybe-unused
* jk/unused-parameters: CodingGuidelines: mention -Wunused-parameter and UNUSED config.mak.dev: enable -Wunused-parameter by default compat: mark unused parameters in win32/mingw functions compat: disable -Wunused-parameter in win32/headless.c compat: disable -Wunused-parameter in 3rd-party code t-reftable-readwrite: mark unused parameter in callback function gc: mark unused config parameter in virtual functions
2 parents 4590f2e + a61bc88 commit c3b92d4

File tree

15 files changed

+46
-33
lines changed

15 files changed

+46
-33
lines changed

Documentation/CodingGuidelines

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ For C programs:
258258
ensure your patch is clear of all compiler warnings we care about,
259259
by e.g. "echo DEVELOPER=1 >>config.mak".
260260

261+
- When using DEVELOPER=1 mode, you may see warnings from the compiler
262+
like "error: unused parameter 'foo' [-Werror=unused-parameter]",
263+
which indicates that a function ignores its argument. If the unused
264+
parameter can't be removed (e.g., because the function is used as a
265+
callback and has to match a certain interface), you can annotate the
266+
individual parameters with the UNUSED keyword, like "int foo UNUSED".
267+
261268
- We try to support a wide range of C compilers to compile Git with,
262269
including old ones. As of Git v2.35.0 Git requires C99 (we check
263270
"__STDC_VERSION__"). You should not use features from a newer C

builtin/gc.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ static int dfs_on_ref(const char *refname UNUSED,
967967
return result;
968968
}
969969

970-
static int should_write_commit_graph(struct gc_config *cfg)
970+
static int should_write_commit_graph(struct gc_config *cfg UNUSED)
971971
{
972972
int result;
973973
struct cg_auto_data data;
@@ -1005,7 +1005,7 @@ static int run_write_commit_graph(struct maintenance_run_opts *opts)
10051005
}
10061006

10071007
static int maintenance_task_commit_graph(struct maintenance_run_opts *opts,
1008-
struct gc_config *cfg)
1008+
struct gc_config *cfg UNUSED)
10091009
{
10101010
prepare_repo_settings(the_repository);
10111011
if (!the_repository->settings.core_commit_graph)
@@ -1040,7 +1040,7 @@ static int fetch_remote(struct remote *remote, void *cbdata)
10401040
}
10411041

10421042
static int maintenance_task_prefetch(struct maintenance_run_opts *opts,
1043-
struct gc_config *cfg)
1043+
struct gc_config *cfg UNUSED)
10441044
{
10451045
if (for_each_remote(fetch_remote, opts)) {
10461046
error(_("failed to prefetch remotes"));
@@ -1051,7 +1051,7 @@ static int maintenance_task_prefetch(struct maintenance_run_opts *opts,
10511051
}
10521052

10531053
static int maintenance_task_gc(struct maintenance_run_opts *opts,
1054-
struct gc_config *cfg)
1054+
struct gc_config *cfg UNUSED)
10551055
{
10561056
struct child_process child = CHILD_PROCESS_INIT;
10571057

@@ -1100,7 +1100,7 @@ static int loose_object_count(const struct object_id *oid UNUSED,
11001100
return 0;
11011101
}
11021102

1103-
static int loose_object_auto_condition(struct gc_config *cfg)
1103+
static int loose_object_auto_condition(struct gc_config *cfg UNUSED)
11041104
{
11051105
int count = 0;
11061106

@@ -1192,12 +1192,12 @@ static int pack_loose(struct maintenance_run_opts *opts)
11921192
}
11931193

11941194
static int maintenance_task_loose_objects(struct maintenance_run_opts *opts,
1195-
struct gc_config *cfg)
1195+
struct gc_config *cfg UNUSED)
11961196
{
11971197
return prune_packed(opts) || pack_loose(opts);
11981198
}
11991199

1200-
static int incremental_repack_auto_condition(struct gc_config *cfg)
1200+
static int incremental_repack_auto_condition(struct gc_config *cfg UNUSED)
12011201
{
12021202
struct packed_git *p;
12031203
int incremental_repack_auto_limit = 10;
@@ -1317,7 +1317,7 @@ static int multi_pack_index_repack(struct maintenance_run_opts *opts)
13171317
}
13181318

13191319
static int maintenance_task_incremental_repack(struct maintenance_run_opts *opts,
1320-
struct gc_config *cfg)
1320+
struct gc_config *cfg UNUSED)
13211321
{
13221322
prepare_repo_settings(the_repository);
13231323
if (!the_repository->settings.core_multi_pack_index) {

compat/mingw.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
243243
static char *unset_environment_variables;
244244

245245
int mingw_core_config(const char *var, const char *value,
246-
const struct config_context *ctx, void *cb)
246+
const struct config_context *ctx UNUSED,
247+
void *cb UNUSED)
247248
{
248249
if (!strcmp(var, "core.hidedotfiles")) {
249250
if (value && !strcasecmp(value, "dotgitonly"))
@@ -453,7 +454,7 @@ static int set_hidden_flag(const wchar_t *path, int set)
453454
return -1;
454455
}
455456

456-
int mingw_mkdir(const char *path, int mode)
457+
int mingw_mkdir(const char *path, int mode UNUSED)
457458
{
458459
int ret;
459460
wchar_t wpath[MAX_PATH];
@@ -597,7 +598,7 @@ int mingw_open (const char *filename, int oflags, ...)
597598
return fd;
598599
}
599600

600-
static BOOL WINAPI ctrl_ignore(DWORD type)
601+
static BOOL WINAPI ctrl_ignore(DWORD type UNUSED)
601602
{
602603
return TRUE;
603604
}
@@ -1085,7 +1086,7 @@ int mkstemp(char *template)
10851086
return git_mkstemp_mode(template, 0600);
10861087
}
10871088

1088-
int gettimeofday(struct timeval *tv, void *tz)
1089+
int gettimeofday(struct timeval *tv, void *tz UNUSED)
10891090
{
10901091
FILETIME ft;
10911092
long long hnsec;
@@ -2252,7 +2253,7 @@ char *mingw_query_user_email(void)
22522253
return get_extended_user_info(NameUserPrincipal);
22532254
}
22542255

2255-
struct passwd *getpwuid(int uid)
2256+
struct passwd *getpwuid(int uid UNUSED)
22562257
{
22572258
static unsigned initialized;
22582259
static char user_name[100];
@@ -2304,7 +2305,7 @@ static sig_handler_t timer_fn = SIG_DFL, sigint_fn = SIG_DFL;
23042305
* length to call the signal handler.
23052306
*/
23062307

2307-
static unsigned __stdcall ticktack(void *dummy)
2308+
static unsigned __stdcall ticktack(void *dummy UNUSED)
23082309
{
23092310
while (WaitForSingleObject(timer_event, timer_interval) == WAIT_TIMEOUT) {
23102311
mingw_raise(SIGALRM);
@@ -2352,7 +2353,7 @@ static inline int is_timeval_eq(const struct timeval *i1, const struct timeval *
23522353
return i1->tv_sec == i2->tv_sec && i1->tv_usec == i2->tv_usec;
23532354
}
23542355

2355-
int setitimer(int type, struct itimerval *in, struct itimerval *out)
2356+
int setitimer(int type UNUSED, struct itimerval *in, struct itimerval *out)
23562357
{
23572358
static const struct timeval zero;
23582359
static int atexit_done;

compat/mingw.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,27 +122,27 @@ struct utsname {
122122
* trivial stubs
123123
*/
124124

125-
static inline int readlink(const char *path, char *buf, size_t bufsiz)
125+
static inline int readlink(const char *path UNUSED, char *buf UNUSED, size_t bufsiz UNUSED)
126126
{ errno = ENOSYS; return -1; }
127-
static inline int symlink(const char *oldpath, const char *newpath)
127+
static inline int symlink(const char *oldpath UNUSED, const char *newpath UNUSED)
128128
{ errno = ENOSYS; return -1; }
129-
static inline int fchmod(int fildes, mode_t mode)
129+
static inline int fchmod(int fildes UNUSED, mode_t mode UNUSED)
130130
{ errno = ENOSYS; return -1; }
131131
#ifndef __MINGW64_VERSION_MAJOR
132132
static inline pid_t fork(void)
133133
{ errno = ENOSYS; return -1; }
134134
#endif
135-
static inline unsigned int alarm(unsigned int seconds)
135+
static inline unsigned int alarm(unsigned int seconds UNUSED)
136136
{ return 0; }
137137
static inline int fsync(int fd)
138138
{ return _commit(fd); }
139139
static inline void sync(void)
140140
{}
141141
static inline uid_t getuid(void)
142142
{ return 1; }
143-
static inline struct passwd *getpwnam(const char *name)
143+
static inline struct passwd *getpwnam(const char *name UNUSED)
144144
{ return NULL; }
145-
static inline int fcntl(int fd, int cmd, ...)
145+
static inline int fcntl(int fd UNUSED, int cmd, ...)
146146
{
147147
if (cmd == F_GETFD || cmd == F_SETFD)
148148
return 0;
@@ -151,17 +151,17 @@ static inline int fcntl(int fd, int cmd, ...)
151151
}
152152

153153
#define sigemptyset(x) (void)0
154-
static inline int sigaddset(sigset_t *set, int signum)
154+
static inline int sigaddset(sigset_t *set UNUSED, int signum UNUSED)
155155
{ return 0; }
156156
#define SIG_BLOCK 0
157157
#define SIG_UNBLOCK 0
158-
static inline int sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
158+
static inline int sigprocmask(int how UNUSED, const sigset_t *set UNUSED, sigset_t *oldset UNUSED)
159159
{ return 0; }
160160
static inline pid_t getppid(void)
161161
{ return 1; }
162162
static inline pid_t getpgid(pid_t pid)
163163
{ return pid == 0 ? getpid() : pid; }
164-
static inline pid_t tcgetpgrp(int fd)
164+
static inline pid_t tcgetpgrp(int fd UNUSED)
165165
{ return getpid(); }
166166

167167
/*

compat/nedmalloc/nedmalloc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ DEALINGS IN THE SOFTWARE.
3131
/*#pragma optimize("a", on)*/
3232
#endif
3333

34+
#pragma GCC diagnostic ignored "-Wunused-parameter"
35+
3436
/*#define FULLSANITYCHECKS*/
3537

3638
#include "nedmalloc.h"

compat/regex/regcomp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
License along with the GNU C Library; if not, see
1818
<http://www.gnu.org/licenses/>. */
1919

20+
#pragma GCC diagnostic ignored "-Wunused-parameter"
21+
2022
#if defined __TANDEM
2123
/* This is currently duplicated from git-compat-utils.h */
2224
# ifdef NO_INTPTR_T

compat/stub/procinfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
* Stub. See sample implementations in compat/linux/procinfo.c and
77
* compat/win32/trace2_win32_process_info.c.
88
*/
9-
void trace2_collect_process_info(enum trace2_process_info_reason reason)
9+
void trace2_collect_process_info(enum trace2_process_info_reason reason UNUSED)
1010
{
1111
}

compat/win32/headless.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <stdlib.h>
1212
#include <wchar.h>
1313

14+
#pragma GCC diagnostic ignored "-Wunused-parameter"
15+
1416
/*
1517
* If `dir` contains the path to a Git exec directory, extend `PATH` to
1618
* include the corresponding `bin/` directory (which is where all those

compat/win32/pthread.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static unsigned __stdcall win32_start_routine(void *arg)
2121
return 0;
2222
}
2323

24-
int pthread_create(pthread_t *thread, const void *unused,
24+
int pthread_create(pthread_t *thread, const void *attr UNUSED,
2525
void *(*start_routine)(void *), void *arg)
2626
{
2727
thread->arg = arg;

compat/win32/pthread.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
#define pthread_mutex_t CRITICAL_SECTION
2020

21-
static inline int return_0(int i) {
21+
static inline int return_0(int i UNUSED) {
2222
return 0;
2323
}
2424
#define pthread_mutex_init(a,b) return_0((InitializeCriticalSection((a)), 0))
@@ -70,7 +70,7 @@ static inline void NORETURN pthread_exit(void *ret)
7070
}
7171

7272
typedef DWORD pthread_key_t;
73-
static inline int pthread_key_create(pthread_key_t *keyp, void (*destructor)(void *value))
73+
static inline int pthread_key_create(pthread_key_t *keyp, void (*destructor)(void *value) UNUSED)
7474
{
7575
return (*keyp = TlsAlloc()) == TLS_OUT_OF_INDEXES ? EAGAIN : 0;
7676
}

compat/win32/syslog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
static HANDLE ms_eventlog;
44

5-
void openlog(const char *ident, int logopt, int facility)
5+
void openlog(const char *ident, int logopt UNUSED, int facility UNUSED)
66
{
77
if (ms_eventlog)
88
return;

compat/win32mmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of
4040
return MAP_FAILED;
4141
}
4242

43-
int git_munmap(void *start, size_t length)
43+
int git_munmap(void *start, size_t length UNUSED)
4444
{
4545
return !UnmapViewOfFile(start);
4646
}

compat/winansi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ enum {
340340
TEXT = 0, ESCAPE = 033, BRACKET = '['
341341
};
342342

343-
static DWORD WINAPI console_thread(LPVOID unused)
343+
static DWORD WINAPI console_thread(LPVOID data UNUSED)
344344
{
345345
unsigned char buffer[BUFFER_SIZE];
346346
DWORD bytes;

config.mak.dev

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ ifeq ($(filter extra-all,$(DEVOPTS)),)
5454
DEVELOPER_CFLAGS += -Wno-empty-body
5555
DEVELOPER_CFLAGS += -Wno-missing-field-initializers
5656
DEVELOPER_CFLAGS += -Wno-sign-compare
57-
DEVELOPER_CFLAGS += -Wno-unused-parameter
5857
endif
5958
endif
6059

t/unit-tests/t-reftable-readwrite.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static ssize_t strbuf_add_void(void *b, const void *data, size_t sz)
2626
return sz;
2727
}
2828

29-
static int noop_flush(void *arg)
29+
static int noop_flush(void *arg UNUSED)
3030
{
3131
return 0;
3232
}

0 commit comments

Comments
 (0)