diff options
author | Jean-Daniel Dupas <devlists@shadowlab.org> | 2012-02-21 20:00:53 +0000 |
---|---|---|
committer | Jean-Daniel Dupas <devlists@shadowlab.org> | 2012-02-21 20:00:53 +0000 |
commit | f57c413e444b441fa75ae8911d183c19b53bdd56 (patch) | |
tree | 8242e39f4ac230f2c3348e89f45d48354439df33 /test/SemaCXX/format-strings.cpp | |
parent | f4b7de1cef3007cc0479775638198287384d9af1 (diff) |
When calling a non variadic format function(vprintf, vscanf, NSLogv, …), warn if the format string argument is a parameter that is not itself declared as a format string with compatible format.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151080 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/format-strings.cpp')
-rw-r--r-- | test/SemaCXX/format-strings.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/test/SemaCXX/format-strings.cpp b/test/SemaCXX/format-strings.cpp index 0d5b62598d..74fc7a7810 100644 --- a/test/SemaCXX/format-strings.cpp +++ b/test/SemaCXX/format-strings.cpp @@ -1,8 +1,11 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -pedantic %s +#include <stdarg.h> + extern "C" { extern int scanf(const char *restrict, ...); extern int printf(const char *restrict, ...); +extern int vprintf(const char *restrict, va_list); } void f(char **sp, float *fp) { @@ -23,11 +26,12 @@ class Foo { public: const char *gettext(const char *fmt) __attribute__((format_arg(2))); - int scanf(const char *restrict, ...) __attribute__((format(scanf, 2, 3))); - int printf(const char *restrict, ...) __attribute__((format(printf, 2, 3))); + int scanf(const char *, ...) __attribute__((format(scanf, 2, 3))); + int printf(const char *, ...) __attribute__((format(printf, 2, 3))); + int printf2(const char *, ...); static const char *gettext_static(const char *fmt) __attribute__((format_arg(1))); - static int printf_static(const char *restrict, ...) __attribute__((format(printf, 1, 2))); + static int printf_static(const char *fmt, ...) __attribute__((format(printf, 1, 2))); }; void h(int *i) { @@ -52,3 +56,23 @@ void rdar8269537(const char *f) test_null_format(__null); // no-warning test_null_format(f); // expected-warning {{not a string literal}} } + +int Foo::printf(const char *fmt, ...) { + va_list ap; + va_start(ap,fmt); + const char * const format = fmt; + vprintf(format, ap); // no-warning + + const char *format2 = fmt; + vprintf(format2, ap); // expected-warning{{format string is not a string literal}} + + return 0; +} + +int Foo::printf2(const char *fmt, ...) { + va_list ap; + va_start(ap,fmt); + vprintf(fmt, ap); // expected-warning{{format string is not a string literal}} + + return 0; +} |