Skip to content

Commit 4b6cf99

Browse files
author
gingold
committed
2009-10-15 Jim Blandy <[email protected]>
* libgnuintl.h (_INTL_MAY_RETURN_STRING_ARG, gettext, dgettext) (dcgettext, ngettext, dngettext, dcngettext): Backport changes from current gettext to provide GCC format_arg attributes. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@152842 138bc75d-0d04-0410-961f-82ee72b054a4
1 parent 3561575 commit 4b6cf99

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

intl/ChangeLog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2009-10-15 Jim Blandy <[email protected]>
2+
3+
* libgnuintl.h (_INTL_MAY_RETURN_STRING_ARG, gettext, dgettext)
4+
(dcgettext, ngettext, dngettext, dcngettext): Backport changes
5+
from current gettext to provide GCC format_arg attributes.
6+
17
2009-08-24 Ralf Wildenhues <[email protected]>
28

39
* configure.ac (AC_PREREQ): Bump to 2.64.

intl/libgnuintl.h

+33-12
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,21 @@ extern "C" {
112112
# define _INTL_ASM(cname)
113113
#endif
114114

115+
/* _INTL_MAY_RETURN_STRING_ARG(n) declares that the given function may return
116+
its n-th argument literally. This enables GCC to warn for example about
117+
printf (gettext ("foo %y")). */
118+
#if __GNUC__ >= 3 && !(__APPLE_CC__ > 1 && defined __cplusplus)
119+
# define _INTL_MAY_RETURN_STRING_ARG(n) __attribute__ ((__format_arg__ (n)))
120+
#else
121+
# define _INTL_MAY_RETURN_STRING_ARG(n)
122+
#endif
123+
115124
/* Look up MSGID in the current default message catalog for the current
116125
LC_MESSAGES locale. If not found, returns MSGID itself (the default
117126
text). */
118127
#ifdef _INTL_REDIRECT_INLINE
119-
extern char *libintl_gettext (const char *__msgid);
128+
extern char *libintl_gettext (const char *__msgid)
129+
_INTL_MAY_RETURN_STRING_ARG (1);
120130
static inline char *gettext (const char *__msgid)
121131
{
122132
return libintl_gettext (__msgid);
@@ -126,13 +136,15 @@ static inline char *gettext (const char *__msgid)
126136
# define gettext libintl_gettext
127137
#endif
128138
extern char *gettext _INTL_PARAMS ((const char *__msgid))
129-
_INTL_ASM (libintl_gettext);
139+
_INTL_ASM (libintl_gettext)
140+
_INTL_MAY_RETURN_STRING_ARG (1);
130141
#endif
131142

132143
/* Look up MSGID in the DOMAINNAME message catalog for the current
133144
LC_MESSAGES locale. */
134145
#ifdef _INTL_REDIRECT_INLINE
135-
extern char *libintl_dgettext (const char *__domainname, const char *__msgid);
146+
extern char *libintl_dgettext (const char *__domainname, const char *__msgid)
147+
_INTL_MAY_RETURN_STRING_ARG (2);
136148
static inline char *dgettext (const char *__domainname, const char *__msgid)
137149
{
138150
return libintl_dgettext (__domainname, __msgid);
@@ -143,14 +155,16 @@ static inline char *dgettext (const char *__domainname, const char *__msgid)
143155
#endif
144156
extern char *dgettext _INTL_PARAMS ((const char *__domainname,
145157
const char *__msgid))
146-
_INTL_ASM (libintl_dgettext);
158+
_INTL_ASM (libintl_dgettext)
159+
_INTL_MAY_RETURN_STRING_ARG (2);
147160
#endif
148161

149162
/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
150163
locale. */
151164
#ifdef _INTL_REDIRECT_INLINE
152165
extern char *libintl_dcgettext (const char *__domainname, const char *__msgid,
153-
int __category);
166+
int __category)
167+
_INTL_MAY_RETURN_STRING_ARG (2);
154168
static inline char *dcgettext (const char *__domainname, const char *__msgid,
155169
int __category)
156170
{
@@ -163,15 +177,17 @@ static inline char *dcgettext (const char *__domainname, const char *__msgid,
163177
extern char *dcgettext _INTL_PARAMS ((const char *__domainname,
164178
const char *__msgid,
165179
int __category))
166-
_INTL_ASM (libintl_dcgettext);
180+
_INTL_ASM (libintl_dcgettext)
181+
_INTL_MAY_RETURN_STRING_ARG (2);
167182
#endif
168183

169184

170185
/* Similar to `gettext' but select the plural form corresponding to the
171186
number N. */
172187
#ifdef _INTL_REDIRECT_INLINE
173188
extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2,
174-
unsigned long int __n);
189+
unsigned long int __n)
190+
_INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2);
175191
static inline char *ngettext (const char *__msgid1, const char *__msgid2,
176192
unsigned long int __n)
177193
{
@@ -184,14 +200,16 @@ static inline char *ngettext (const char *__msgid1, const char *__msgid2,
184200
extern char *ngettext _INTL_PARAMS ((const char *__msgid1,
185201
const char *__msgid2,
186202
unsigned long int __n))
187-
_INTL_ASM (libintl_ngettext);
203+
_INTL_ASM (libintl_ngettext)
204+
_INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2);
188205
#endif
189206

190207
/* Similar to `dgettext' but select the plural form corresponding to the
191208
number N. */
192209
#ifdef _INTL_REDIRECT_INLINE
193210
extern char *libintl_dngettext (const char *__domainname, const char *__msgid1,
194-
const char *__msgid2, unsigned long int __n);
211+
const char *__msgid2, unsigned long int __n)
212+
_INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
195213
static inline char *dngettext (const char *__domainname, const char *__msgid1,
196214
const char *__msgid2, unsigned long int __n)
197215
{
@@ -205,15 +223,17 @@ extern char *dngettext _INTL_PARAMS ((const char *__domainname,
205223
const char *__msgid1,
206224
const char *__msgid2,
207225
unsigned long int __n))
208-
_INTL_ASM (libintl_dngettext);
226+
_INTL_ASM (libintl_dngettext)
227+
_INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
209228
#endif
210229

211230
/* Similar to `dcgettext' but select the plural form corresponding to the
212231
number N. */
213232
#ifdef _INTL_REDIRECT_INLINE
214233
extern char *libintl_dcngettext (const char *__domainname,
215234
const char *__msgid1, const char *__msgid2,
216-
unsigned long int __n, int __category);
235+
unsigned long int __n, int __category)
236+
_INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
217237
static inline char *dcngettext (const char *__domainname,
218238
const char *__msgid1, const char *__msgid2,
219239
unsigned long int __n, int __category)
@@ -229,7 +249,8 @@ extern char *dcngettext _INTL_PARAMS ((const char *__domainname,
229249
const char *__msgid2,
230250
unsigned long int __n,
231251
int __category))
232-
_INTL_ASM (libintl_dcngettext);
252+
_INTL_ASM (libintl_dcngettext)
253+
_INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
233254
#endif
234255

235256

0 commit comments

Comments
 (0)