summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/printf-block.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-06-21 01:08:35 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-06-21 01:08:35 +0000
commitc7b0bdffe75c05aeb4a0689086d899c5527c3c7b (patch)
tree9abab9b93791ace8e96b7e5f4c48dce1668ea7ec /clang/test/SemaCXX/printf-block.cpp
parent15b4cafd2ca3459bf33f909f1aa65b9eb8caad74 (diff)
downloadbcm5719-llvm-c7b0bdffe75c05aeb4a0689086d899c5527c3c7b.tar.gz
bcm5719-llvm-c7b0bdffe75c05aeb4a0689086d899c5527c3c7b.zip
If an object (such as a std::string) with an appropriate c_str() member function
is passed to a variadic function in a position where a format string indicates that c_str()'s return type is desired, provide a note suggesting that the user may have intended to call the c_str() member. Factor the non-POD-vararg checking out of DefaultVariadicArgumentPromotion and move it to SemaChecking in order to facilitate this. Factor the call checking out of function call checking and block call checking, and extend it to cover constructor calls too. Patch by Sam Panzer! llvm-svn: 158887
Diffstat (limited to 'clang/test/SemaCXX/printf-block.cpp')
-rw-r--r--clang/test/SemaCXX/printf-block.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/printf-block.cpp b/clang/test/SemaCXX/printf-block.cpp
new file mode 100644
index 00000000000..a7d266bac5c
--- /dev/null
+++ b/clang/test/SemaCXX/printf-block.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wformat -verify %s -Wno-error=non-pod-varargs
+
+int (^block) (int, const char *,...) __attribute__((__format__(__printf__,2,3))) = ^ __attribute__((__format__(__printf__,2,3))) (int arg, const char *format,...) {return 5;};
+
+class HasNoCStr {
+ const char *str;
+ public:
+ HasNoCStr(const char *s): str(s) { }
+ const char *not_c_str() {return str;}
+};
+
+void test_block() {
+ const char str[] = "test";
+ HasNoCStr hncs(str);
+ int n = 4;
+ block(n, "%s %d", str, n); // no-warning
+ block(n, "%s %s", hncs, n); // expected-warning{{cannot pass non-POD object of type 'HasNoCStr' to variadic function; expected type from format string was 'char *'}} expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
+}
OpenPOWER on IntegriCloud