This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
FYI: -Wunused warning in cp-namespace.c with old glibc...
- From: Joel Brobecker <brobecker at adacore dot com>
- To: gdb-patches at sourceware dot org
- Date: Wed, 30 Dec 2009 14:48:16 +0400
- Subject: FYI: -Wunused warning in cp-namespace.c with old glibc...
Hello,
We're still supporting some pretty old x86-linux distributions at
AdaCore, and one of them comes with a now antiquated version of
the glic. And unfortunately, this version of glic plays some tricks
with strncpy, while these tricks are disabled on older glibcs
for GCC 3.2+:
/* Copy no more than N characters of SRC to DEST. */
#ifndef _HAVE_STRING_ARCH_strncpy
# if __GNUC_PREREQ (3, 2)
# define strncpy(dest, src, n) __builtin_strncpy (dest, src, n)
# else
# define strncpy(dest, src, n) \
(__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n) \
? (strlen (src) + 1 >= ((size_t) (n)) \
? (char *) memcpy (dest, src, n) \
: strncpy (dest, src, n)) \
: strncpy (dest, src, n)))
# endif
#endif
On the older system, we end up getting a warning-turned-error:
[...]/gdb/cp-namespace.c: In function 'cp_lookup_transparent_type_loop':
[...]/gdb/cp-namespace.c:542: error: value computed is not used
The fix we applied locally, is to cast the function return to void.
I don't think that this part would be of interest for the FSF tree
(it's not exactly great to add an apparently useless cast), so I propose
we don't apply it, but I thought I'd still post it, in case someone else
might need it (or others think it should go in). For now, I'll assume
we don't want it.
2009-12-30 Joel Brobecker <brobecker@adacore.com>
Work around a -Wunused warning when glibc is too old.
* cp-namespace.c (cp_lookup_transparent_type_loop): Add cast to
void in function return to avoid a compiler warning.
"tested" by rebuilding GDB. I'll also get the nightly build results
tomorrow, but I didn't want to spend too much effort on this one.
--
Joel
commit cdf20aaf0a8b39a1f1ee427570a717f1c44ba272
Author: brobecke <brobecke@f8352e7e-cb20-0410-8ce7-b5d9e71c585c>
Date: Wed Dec 30 10:28:08 2009 +0000
Work around a -Wunused warning when glibc is too old.
* cp-namespace.c (cp_lookup_transparent_type_loop): Add cast to
void in function return to avoid a compiler warning.
diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index a7a387b..35bb36c 100644
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -539,7 +539,10 @@ cp_lookup_transparent_type_loop (const char *name, const char *scope,
full_name = alloca (scope_length + 2 + strlen (name) + 1);
strncpy (full_name, scope, scope_length);
- strncpy (full_name + scope_length, "::", 2);
+ /* Cast to void the return value of the following strncpy to avoid
+ a -Wunused warning from GCC when the glibc is too old (observed
+ with a 2.3.2 libc, while everything was fine with a 2.4 glibc). */
+ (void) strncpy (full_name + scope_length, "::", 2);
strcpy (full_name + scope_length + 2, name);
return basic_lookup_transparent_type (full_name);