* [PATCH] ctype.h: Fix unused variable warnings
@ 2020-07-16 8:28 Sebastian Huber
2020-07-16 9:31 ` Corinna Vinschen
0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Huber @ 2020-07-16 8:28 UTC (permalink / raw)
To: newlib
From: Aschref Ben Thabet <aschref.ben-thabet@embedded-brains.de>
If __HAVE_LOCALE_INFO__ is not defined, then the locale in the
locale-specific ctype functions is ignored. In the previous
implementation this resulted in compiler warnings. For example:
int main()
{
locale_t locale;
locale = duplocale(uselocale((locale_t)0));
isspace_l('x', locale);
return 0;
}
gcc -Wall main.c
main.c: In function 'main':
main.c:6:11: warning: variable 'locale' set but not used [-Wunused-but-set-variable]
6 | locale_t locale;
| ^~~~~~
---
newlib/libc/include/ctype.h | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/newlib/libc/include/ctype.h b/newlib/libc/include/ctype.h
index a0009af17..8b1013ac0 100644
--- a/newlib/libc/include/ctype.h
+++ b/newlib/libc/include/ctype.h
@@ -66,6 +66,9 @@ extern int toascii_l (int __c, locale_t __l);
#define _X 0100
#define _B 0200
+/* For C++ backward-compatibility only. */
+extern __IMPORT const char _ctype_[];
+
#ifdef __HAVE_LOCALE_INFO__
const char *__locale_ctype_ptr (void);
#else
@@ -108,7 +111,12 @@ const char *__locale_ctype_ptr (void);
#ifdef __HAVE_LOCALE_INFO__
const char *__locale_ctype_ptr_l (locale_t);
#else
-#define __locale_ctype_ptr_l(l) _ctype_
+static __inline char *
+__locale_ctype_ptr_l(locale_t _l)
+{
+ (void)_l;
+ return __locale_ctype_ptr();
+}
#endif
#define __ctype_lookup_l(__c,__l) ((__locale_ctype_ptr_l(__l)+sizeof(""[__c]))[(int)(__c)])
@@ -170,9 +178,6 @@ const char *__locale_ctype_ptr_l (locale_t);
#endif /* !__cplusplus */
-/* For C++ backward-compatibility only. */
-extern __IMPORT const char _ctype_[];
-
_END_STD_C
#endif /* _CTYPE_H_ */
--
2.26.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] ctype.h: Fix unused variable warnings
2020-07-16 8:28 [PATCH] ctype.h: Fix unused variable warnings Sebastian Huber
@ 2020-07-16 9:31 ` Corinna Vinschen
0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2020-07-16 9:31 UTC (permalink / raw)
To: Sebastian Huber; +Cc: newlib
On Jul 16 10:28, Sebastian Huber wrote:
> From: Aschref Ben Thabet <aschref.ben-thabet@embedded-brains.de>
>
> If __HAVE_LOCALE_INFO__ is not defined, then the locale in the
> locale-specific ctype functions is ignored. In the previous
> implementation this resulted in compiler warnings. For example:
>
> int main()
> {
> locale_t locale;
> locale = duplocale(uselocale((locale_t)0));
> isspace_l('x', locale);
> return 0;
> }
>
> gcc -Wall main.c
> main.c: In function 'main':
> main.c:6:11: warning: variable 'locale' set but not used [-Wunused-but-set-variable]
> 6 | locale_t locale;
> | ^~~~~~
> ---
> newlib/libc/include/ctype.h | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
Pushed.
Thanks,
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-07-16 9:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-16 8:28 [PATCH] ctype.h: Fix unused variable warnings Sebastian Huber
2020-07-16 9:31 ` Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).