diff options
author | Richard Trieu <rtrieu@google.com> | 2011-10-28 00:41:25 +0000 |
---|---|---|
committer | Richard Trieu <rtrieu@google.com> | 2011-10-28 00:41:25 +0000 |
commit | 03cf7b70e0d643b28b17870ab78940e7006b4313 (patch) | |
tree | 40ff561f212dcc054eeb6b07d1dd0330fe5bd5e4 /clang/test/Sema/format-strings-scanf.c | |
parent | 080a499ee0e96d3fc9fc8587ef4fc663c364c23d (diff) | |
download | bcm5719-llvm-03cf7b70e0d643b28b17870ab78940e7006b4313.tar.gz bcm5719-llvm-03cf7b70e0d643b28b17870ab78940e7006b4313.zip |
Fix for PR9751 to change the behavior of -Wformat warnings. If the format
string is part of the function call, then there is no difference. If the
format string is not, the warning will point to the call site and a note
will point to where the format string is.
Fix-it hints for strings are moved to the note if a note is emitted. This will
prevent changes to format strings that may be used in multiple places.
llvm-svn: 143168
Diffstat (limited to 'clang/test/Sema/format-strings-scanf.c')
-rw-r--r-- | clang/test/Sema/format-strings-scanf.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/test/Sema/format-strings-scanf.c b/clang/test/Sema/format-strings-scanf.c index 42b6c03ffbf..ee559daef61 100644 --- a/clang/test/Sema/format-strings-scanf.c +++ b/clang/test/Sema/format-strings-scanf.c @@ -32,3 +32,15 @@ void bad_length_modifiers(char *s, void *p, wchar_t *ws, long double *ld) { scanf("%ls", ws); // no-warning scanf("%#.2Lf", ld); // expected-warning{{invalid conversion specifier '#'}} } + +// Test that the scanf call site is where the warning is attached. If the +// format string is somewhere else, point to it in a note. +void pr9751() { + int *i; + const char kFormat1[] = "%00d"; // expected-note{{format string is defined here}}} + scanf(kFormat1, i); // expected-warning{{zero field width in scanf format string is unused}} + scanf("%00d", i); // expected-warning{{zero field width in scanf format string is unused}} + const char kFormat2[] = "%["; // expected-note{{format string is defined here}}} + scanf(kFormat2, &i); // expected-warning{{no closing ']' for '%[' in scanf format string}} + scanf("%[", &i); // expected-warning{{no closing ']' for '%[' in scanf format string}} +} |