Paul Eggert wrote:
> * lib/obstack.in.h (obstack_free): Omit unnecessary cast.
> * lib/printf-args.c (PRINTF_FETCHARGS): Omit unnecessary casts.
> * lib/vma-iter.c (rof_open): Omit unnecessary casts.
These patches are not all good.
> diff --git a/lib/obstack.in.h b/lib/obstack.in.h
> index b74c0908e1..b68e8fc9b9 100644
> --- a/lib/obstack.in.h
> +++ b/lib/obstack.in.h
> @@ -487,7 +487,7 @@ extern int obstack_exit_failure;
> # define obstack_free(OBSTACK, OBJ) \
> __extension__
> \
> ({ struct obstack *__o = (OBSTACK);
> \
> - void *__obj = (void *) (OBJ); \
> + void *__obj = OBJ; \
Here, there is still a need for parentheses around OBJ, namely when
this macro is used in C++ mode and OBJ is something like
new FooBar<int,long>()
with at least two template parameters.
> diff --git a/lib/printf-args.c b/lib/printf-args.c
> index 2f7bf3da00..f2d0a58e23 100644
> --- a/lib/printf-args.c
> +++ b/lib/printf-args.c
> @@ -208,13 +208,10 @@ PRINTF_FETCHARGS (va_list args, arguments *a)
> debug output. Use a fallback in this case. */
> if (ap->a.a_wide_string == NULL)
> {
> + /* No need for wide character constants, as these are
> + silently converted correctly. */
> static const wchar_t wide_null_string[] =
> - {
> - (wchar_t)'(',
> - (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L',
> - (wchar_t)')',
> - (wchar_t)0
> - };
> + { '(', 'N', 'U', 'L', 'L', ')', 0 };
Confusing wchar_t typed expressions with char typed expressions is a
slippery slope, not good for maintenance. Better keep the constants
typed as wchar_t.
> diff --git a/lib/vma-iter.c b/lib/vma-iter.c
> index 85838060e1..1575d38be5 100644
> --- a/lib/vma-iter.c
> +++ b/lib/vma-iter.c
> @@ -254,8 +254,8 @@ rof_open (struct rofile *rof, const char *filename)
> if (rof->auxmap != NULL)
> munmap (rof->auxmap, rof->auxmap_length);
> }
> - rof->auxmap = (void *) mmap ((void *) 0, size, PROT_READ | PROT_WRITE,
> - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
> + rof->auxmap = mmap ((void *) 0, size, PROT_READ | PROT_WRITE,
> + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
> if (rof->auxmap == (void *) -1)
> {
> close (fd);
I disagree with this patch. The casts are there for platforms where mmap()
returns a 'caddr_t', i.e. 'char *', not 'void *'. The warning in this file
(and all other *.c files) are now silenced through gl_CC_GNULIB_WARNINGS anyway.
2026-05-08 Bruno Haible <[email protected]>
Revisit some -Wuseless-cast changes.
* lib/obstack.in.h (obstack_free): Restore parentheses around macro
argument.
* lib/printf-args.c (PRINTF_FETCHARGS): Do use wchar_t-typed constants.
* lib/vma-iter.c (rof_open): Revert last change. Warning now silenced
through gl_CC_GNULIB_WARNINGS.
diff --git a/lib/obstack.in.h b/lib/obstack.in.h
index b68e8fc9b9..496307748d 100644
--- a/lib/obstack.in.h
+++ b/lib/obstack.in.h
@@ -487,7 +487,7 @@ extern int obstack_exit_failure;
# define obstack_free(OBSTACK, OBJ) \
__extension__
\
({ struct obstack *__o = (OBSTACK);
\
- void *__obj = OBJ; \
+ void *__obj = (OBJ); \
if ((_OBSTACK_CPTR) __o->chunk < (_OBSTACK_CPTR) __obj \
&& (_OBSTACK_CPTR) __obj < (_OBSTACK_CPTR) __o->chunk_limit)
\
__o->next_free = __o->object_base = (char *) __obj; \
diff --git a/lib/printf-args.c b/lib/printf-args.c
index f2d0a58e23..fc582b5af8 100644
--- a/lib/printf-args.c
+++ b/lib/printf-args.c
@@ -208,10 +208,8 @@ PRINTF_FETCHARGS (va_list args, arguments *a)
debug output. Use a fallback in this case. */
if (ap->a.a_wide_string == NULL)
{
- /* No need for wide character constants, as these are
- silently converted correctly. */
static const wchar_t wide_null_string[] =
- { '(', 'N', 'U', 'L', 'L', ')', 0 };
+ { L'(', L'N', L'U', L'L', L'L', L')', 0 };
ap->a.a_wide_string = wide_null_string;
}
break;
diff --git a/lib/vma-iter.c b/lib/vma-iter.c
index 1575d38be5..85838060e1 100644
--- a/lib/vma-iter.c
+++ b/lib/vma-iter.c
@@ -254,8 +254,8 @@ rof_open (struct rofile *rof, const char *filename)
if (rof->auxmap != NULL)
munmap (rof->auxmap, rof->auxmap_length);
}
- rof->auxmap = mmap ((void *) 0, size, PROT_READ | PROT_WRITE,
- MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ rof->auxmap = (void *) mmap ((void *) 0, size, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (rof->auxmap == (void *) -1)
{
close (fd);
@@ -264,7 +264,7 @@ rof_open (struct rofile *rof, const char *filename)
rof->auxmap_length = size;
rof->auxmap_start = (unsigned long) rof->auxmap;
rof->auxmap_end = rof->auxmap_start + size;
- rof->buffer = rof->auxmap;
+ rof->buffer = (char *) rof->auxmap;
retry:
/* Restart. */
if (lseek (fd, 0, SEEK_SET) < 0)