[cfe-dev] clang missing a warning.

Paul Curtis plc at rowley.co.uk
Fri Jun 28 09:38:46 PDT 2013


> Hi,
> 
> How do I get clang to detect the following error #include <stdio.h>
> 
> extern test_printf(const char *format, ...);
> 
> int main()
> {
>         int a,b;
>         a = 1;
>         b = 2;
>         test_printf("Hello a=0x%x, b=0x%x, c=0x%x\n", a, b);
>         printf("Hello a=0x%x, b=0x%x, c=0x%x\n", a, b);
> 
>         return 0;
> }
> 
> When compiled with:
> clang -c -g -O0 -o test.o test.c
> 
> It correctly warns about the lack of a third param in the "printf()" line.
> How do I get it to warn on the test_printf() line?

You must adorn the prototype with information for the compiler--that it
accepts a format string, and where to find the format string, and where to
find the fixed parameters:

void test_printf(const char *fmt, ...) __attribute__((__format__ (printf, 1,
2)));

See:

http://clang.llvm.org/docs/LanguageExtensions.html#format-string-checking

--
Paul Curtis, Rowley Associates Ltd   http://www.rowley.co.uk
SolderCore Development Platform      http://www.soldercore.com






More information about the cfe-dev mailing list