[cfe-commits] [PATCH] format attribute improvements.
Jean-Daniel Dupas
devlists at shadowlab.org
Wed Jan 25 10:41:58 PST 2012
Le 25 janv. 2012 à 18:33, jahanian a écrit :
>
> On Jan 24, 2012, at 4:39 PM, Jean-Daniel Dupas wrote:
>
>> Hi,
>>
>>
>> 3-macros: In Obj-C and CoreFoundation, the recommended way to localize string are respectively to use NSLocalizedString(key, comment) and CFCopyLocalizedString(key, comment) macros family.
>> It is common to use these macros as format string, but as they expand to method/function call, clang will warn about "non literal string" used as format string.
>> So, this patch is a tentative to prevent diagnostic for this common usage. It inhibits the "non literal string format" diagnostic when the format type if NS/CFstring and the format argument is a macro expansion.
>> Note that while the CFCopyLocalizedString() expands to a function properly tagged with the "format_arg" attribute, we can't rely on it, because interpreting the 'key' parameter as a format string is incorrect IMHO.
>> It is a common practice to use some kind of descriptive name for the key (i.e. "UNEXPECTED_ERROR_TITLE") instead of the string value ("An unexpected error occurred: %@").
>> Moreover, NSLocalizedString() does not use the "format_arg" attribute.
>>
>
> I don't seem to be getting the warning on the test case, and I don't think you have yet checked in the patch.
You're right. The tested warning is not enabled by default, and I forgot to add it to the test command line (or to enable it using pragma diagnostic).
I attach an updated version of the remaining patch with this issue fixed.
> - Fariborz
>
>> If you have a better idea to limit diagnostic for this common pattern, let me know.
>>
>>
>>
>> -- Jean-Daniel
>>
>>
>>
>> <1-type.patch><2-block.patch><3-macros.patch><4-objc-const.patch><5-vprintf.patch>_______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-- Jean-Daniel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1-type.patch
Type: application/octet-stream
Size: 12067 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120125/32644ced/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2-vprintf.patch
Type: application/octet-stream
Size: 4876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120125/32644ced/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 3-macros.patch
Type: application/octet-stream
Size: 1862 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120125/32644ced/attachment-0002.obj>
More information about the cfe-commits
mailing list