bug-gettext
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gettext] _INTL_MAY_RETURN_STRING_ARG -vs- clang


From: Bruno Haible
Subject: Re: [bug-gettext] _INTL_MAY_RETURN_STRING_ARG -vs- clang
Date: Tue, 03 Jul 2018 23:35:34 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-128-generic; KDE/5.18.0; x86_64; ; )

Hi Tom,

> I was trying to get gdb to build warning-free on macOS.  Most of the
> warnings came from the `_' macro.
> 
> You can see the start of the thread here:
>     https://sourceware.org/ml/gdb-patches/2018-06/msg00728.html
> It continues in the next month:
>     https://sourceware.org/ml/gdb-patches/2018-07/msg00010.html
> 
> gdb and gcc are still using 0.12.  I'm not sure why.  But, I looked and
> the problems still apply to git master.
> 
> 
> Currently gettext-runtime/intl/libgnuintl.in.h has:
> 
>     /* _INTL_MAY_RETURN_STRING_ARG(n) declares that the given function may 
> return
>        its n-th argument literally.  This enables GCC to warn for example 
> about
>        printf (gettext ("foo %y")).  */
>     #if defined __GNUC__ && __GNUC__ >= 3 && !(defined __APPLE_CC__ && 
> __APPLE_CC__ > 1 && defined __cplusplus)
>     # define _INTL_MAY_RETURN_STRING_ARG(n) __attribute__ ((__format_arg__ 
> (n)))
>     #else
>     # define _INTL_MAY_RETURN_STRING_ARG(n)
>     #endif
> 
> However, it seems that clang handles __format_arg__ just fine.

Thanks for the report. Done through this commit
http://git.savannah.gnu.org/gitweb/?p=gettext.git;a=commitdiff;h=bd6a52241c7c83c90e043ace2082a2508d273f55

> So, first, this test ought to be refined somehow.  I don't know exactly
> how, though.  Perhaps detecting clang would be sufficient?

It is dangerous to enable it unconditionally, because that would lead
to syntax errors in older versions of clang.

According to the clang svn repository, __format_arg__ support was added
on or before 2011-01-21, and since according to http://releases.llvm.org/
the next major release was clang 3.0, it seems safe to assume that clang
3.0 and newer support the __format_arg__ attribute.


> Second, there is code like this:
> 
>     #ifdef _INTL_REDIRECT_INLINE
>     extern char *libintl_gettext (const char *__msgid)
>            _INTL_MAY_RETURN_STRING_ARG (1);
>     static inline char *gettext (const char *__msgid)
>     {
>       return libintl_gettext (__msgid);
>     }
>     #else
>     [...]
> 
> Here, the inline "gettext" must also be marked as _INTL_MAY_RETURN_STRING_ARG.
> 
> I think this applies to gettext, dgettext, dcgettext, ngettext,
> dngettext, and dcngettext.

Yes. Done through this commit:

http://git.savannah.gnu.org/gitweb/?p=gettext.git;a=commitdiff;h=113893dce80358a4ae0d9463ce73c5670c81cf0c

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]