[cfe-dev] clang missing a warning.

Dmitri Gribenko gribozavr at gmail.com
Fri Jun 28 09:22:06 PDT 2013


On Fri, Jun 28, 2013 at 9:13 AM, James Courtier-Dutton
<james.dutton at gmail.com> wrote:
> 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

Hi James,

Put __attribute__((format(printf(1,2))) on test_printf.

http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html

Dmitri

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/



More information about the cfe-dev mailing list