From 776ea503e04f12b9599fb14430fee772ba61e9b8 Mon Sep 17 00:00:00 2001 From: Andrei Lepikhov Date: Tue, 24 Nov 2026 13:54:41 +0100 Subject: [PATCH v0] Silence -Wunused-but-set-global warnings with libedit Commit 4e108ce790e removed the set-but-unused static globals reported by clang 23's new -Wunused-but-set-global warning, but two more remain in psql. They show up only when psql is built against a line-editing library that lacks some optional functions, such as the libedit that ships with macOS. Put the declarations and all assignments under the same preprocessor conditions as the reads. --- src/bin/psql/input.c | 6 ++++++ src/bin/psql/tab-complete.in.c | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c index 6d37359fc96..5412055c572 100644 --- a/src/bin/psql/input.c +++ b/src/bin/psql/input.c @@ -33,7 +33,9 @@ static bool useHistory; static char *psql_history; +#if defined(HAVE_HISTORY_TRUNCATE_FILE) && defined(HAVE_APPEND_HISTORY) static int history_lines_added; +#endif /* @@ -161,8 +163,10 @@ pg_send_history(PQExpBuffer history_buf) prev_hist = pg_strdup(s); /* And send it to readline */ add_history(s); +#if defined(HAVE_HISTORY_TRUNCATE_FILE) && defined(HAVE_APPEND_HISTORY) /* Count lines added to history for use later */ history_lines_added++; +#endif } } @@ -364,7 +368,9 @@ initializeInput(int flags) useHistory = true; using_history(); +#if defined(HAVE_HISTORY_TRUNCATE_FILE) && defined(HAVE_APPEND_HISTORY) history_lines_added = 0; +#endif histfile = GetVariable(pset.vars, "HISTFILE"); diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c index 96de78cd087..36353960a9e 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -222,7 +222,9 @@ static int completion_max_records; * macros) and then used by the completion callback functions. Ugly but there * is no better way. */ +#ifdef USE_FILENAME_QUOTING_FUNCTIONS static char completion_last_char; /* last char of input word */ +#endif static const char *completion_charp; /* to pass a string */ static const char *const *completion_charpp; /* to pass a list of strings */ static const VersionedQuery *completion_vquery; /* to pass a VersionedQuery */ @@ -1950,8 +1952,10 @@ psql_completion(const char *text, int start, int end) char *text_copy = pnstrdup(rl_line_buffer + start, end - start); text = text_copy; +#ifdef USE_FILENAME_QUOTING_FUNCTIONS /* Remember last char of the given input word. */ completion_last_char = (end > start) ? text[end - start - 1] : '\0'; +#endif /* We usually want the append character to be a space. */ rl_completion_append_character = ' '; -- 2.56.1