I noticed a problem when using pgettext on debian testing. When
I compile the following small test program
#define ENABLE_NLS 1
#include "lib/gettext.h"
int test(){
if (pgettext ("This is", "a bug") == "I guess")
return 1;
}
I get the following error:
fritz@debian:~/pspp/gnulib$ gcc -c test.c
In file included from test.c:2:
test.c: In function ‘test’:
lib/gettext.h:123:67: error: ‘LC_MESSAGES’ undeclared (first use in this
function)
123 | pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid,
LC_MESSAGES)
|
^~~~~~~~~~~
test.c:5:7: note: in expansion of macro ‘pgettext’
5 | if (pgettext ("This is", "a bug") == "I guess")
| ^~~~~~~~
lib/gettext.h:123:67: note: each undeclared identifier is reported only once
for each function it appears in
123 | pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid,
LC_MESSAGES)
|
^~~~~~~~~~~
test.c:5:7: note: in expansion of macro ‘pgettext’
5 | if (pgettext ("This is", "a bug") == "I guess")
| ^~~~~~~~
When I compile with
gcc -c -O2 test.c
then it works. I guess the reason is that gettext.h includes
/usr/include/libintl.h which
has the following part which includes „locale.h“ only when we are compiling
with optimization.
/* Optimized version of the function above. */
#if defined __OPTIMIZE__ && !defined __cplusplus
/* We need NULL for `gettext'. */
# define __need_NULL
# include <stddef.h>
/* We need LC_MESSAGES for `dgettext'. */
# include <locale.h>
…
I think gettext should always include <locale.h> or should somehow make sure
that LC_MESSAGES are defined or not used.
Best regards
Friedrich