diff options
author | Jean-Daniel Dupas <devlists@shadowlab.org> | 2012-02-07 19:01:42 +0000 |
---|---|---|
committer | Jean-Daniel Dupas <devlists@shadowlab.org> | 2012-02-07 19:01:42 +0000 |
commit | 6255bd14f0184b23e990ef57d652f4a63ea5d223 (patch) | |
tree | 567d416eb42dabe80a075eef27b6eb605203c922 /clang/test/SemaCXX/format-strings.cpp | |
parent | 57d2c785727daa20cd576fa6cd123ce4f63df6dc (diff) | |
download | llvm-6255bd14f0184b23e990ef57d652f4a63ea5d223.zip llvm-6255bd14f0184b23e990ef57d652f4a63ea5d223.tar.gz llvm-6255bd14f0184b23e990ef57d652f4a63ea5d223.tar.bz2 |
Implements support of format_arg attribute on C++ member.
llvm-svn: 149998
Diffstat (limited to 'clang/test/SemaCXX/format-strings.cpp')
-rw-r--r-- | clang/test/SemaCXX/format-strings.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/clang/test/SemaCXX/format-strings.cpp b/clang/test/SemaCXX/format-strings.cpp index 4f5b74d..8b0b00d 100644 --- a/clang/test/SemaCXX/format-strings.cpp +++ b/clang/test/SemaCXX/format-strings.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -pedantic %s extern "C" { extern int scanf(const char *restrict, ...); @@ -17,3 +17,25 @@ void f(char **sp, float *fp) { void g() { printf("%ls", "foo"); // expected-warning{{format specifies type 'wchar_t *' but the argument has type 'const char *'}} } + +// Test that we properly handle format_idx on C++ members. +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))); + + static const char *gettext_static(const char *fmt) __attribute__((format_arg(1))); + static int printf_static(const char *restrict, ...) __attribute__((format(printf, 1, 2))); +}; + +void h(int *i) { + Foo foo; + foo.scanf("%d"); // expected-warning{{more '%' conversions than data arguments}} + foo.printf("%d", i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}} + Foo::printf_static("%d", i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}} + + printf(foo.gettext("%d"), i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}} + printf(Foo::gettext_static("%d"), i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}} +} |