[cfe-commits] r146326 - in /cfe/trunk: include/clang/Analysis/Analyses/FormatString.h lib/Analysis/ScanfFormatString.cpp lib/Sema/SemaChecking.cpp test/Analysis/taint-generic.c test/Analysis/taint-tester.c test/Sema/format-strings-fixit.c test/Se

Hans Wennborg hans at chromium.org
Wed Dec 28 05:23:12 PST 2011


Hi Nico,

On Sat, Dec 24, 2011 at 1:33 AM, Nico Weber <thakis at chromium.org> wrote:
> Hi Hans,
>
> I have some c++ code that also uses 'a' as modifier. It used to build
> fine with clang, but now it no longer does:
>
> $ cat test.cc
> #include <stdio.h>
> #include <stdlib.h>
>
> int main() {
>  char* buff;
>  scanf("%a[^)]", &buff);
>  printf("%s\n", buff);
>  free(buff);
> }
> $ clang++ test.cc -o foo
> test.cc:6:11: warning: conversion specifies type 'float *' but the
> argument has type 'char **' [-Wformat]
>  scanf("%a[^)]", &buff);
>         ~^       ~~~~~
> 1 warning generated.
>
> What's the motivation for not allowing this extension in more cases?
> gcc seems to support it in c++, c++0x, and c (but not in c99).

I've landed r147310 which allows for 'a' as a length modifier in C++ too.

The motivation for not allowing it in all cases is that C99 introduced
'a' as a conversion specifier (for float). So the "%as" format string
actually means different things in C90 (scan and allocate a string)
and C99 (scan a float and an 's').

Since C++03 refers to the C90 library, it makes sense to allow it
there, but C++11 uses the C99 library, so I don't think it should be
allowed there.

Thanks,
Hans




More information about the cfe-commits mailing list