summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/format-strings.cpp
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-10-02 01:49:54 +0000
committerJordan Rose <jordan_rose@apple.com>2012-10-02 01:49:54 +0000
commit3c14b2339de13053eb0a1dffbeaac60b49c37407 (patch)
treeb1719d3aa671ee49ed716b6cec9570a6baa3c713 /clang/test/SemaCXX/format-strings.cpp
parent380a74a339acce977eaa3858e106c9e74d18f126 (diff)
downloadbcm5719-llvm-3c14b2339de13053eb0a1dffbeaac60b49c37407.tar.gz
bcm5719-llvm-3c14b2339de13053eb0a1dffbeaac60b49c37407.zip
-Wformat: Don't check format strings in uninstantiated templates.
Also applies to -Wnonnull, -Wtype-safety, and -Wnon-pod-varargs. All of these can be better checked at instantiation time. This change does not actually affect regular CallExpr function calls, since the checks there only happen after overload resolution. However, it will affect Objective-C method calls. <rdar://problem/12373934> llvm-svn: 164984
Diffstat (limited to 'clang/test/SemaCXX/format-strings.cpp')
-rw-r--r--clang/test/SemaCXX/format-strings.cpp60
1 files changed, 59 insertions, 1 deletions
diff --git a/clang/test/SemaCXX/format-strings.cpp b/clang/test/SemaCXX/format-strings.cpp
index 6b0df293537..299aa81bb16 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 -Wformat-nonliteral -pedantic %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -pedantic -fblocks %s
#include <stdarg.h>
@@ -75,3 +75,61 @@ int Foo::printf2(const char *fmt, ...) {
return 0;
}
+
+
+namespace Templates {
+ template<typename T>
+ void my_uninstantiated_print(const T &arg) {
+ printf("%d", arg); // no-warning
+ }
+
+ template<typename T>
+ void my_print(const T &arg) {
+ printf("%d", arg); // expected-warning {{format specifies type 'int' but the argument has type 'const char *'}}
+ }
+
+ void use_my_print() {
+ my_print("abc"); // expected-note {{requested here}}
+ }
+
+
+ template<typename T>
+ class UninstantiatedPrinter {
+ public:
+ static void print(const T &arg) {
+ printf("%d", arg); // no-warning
+ }
+ };
+
+ template<typename T>
+ class Printer {
+ void format(const char *fmt, ...) __attribute__((format(printf,2,3)));
+ public:
+
+ void print(const T &arg) {
+ format("%d", arg); // expected-warning {{format specifies type 'int' but the argument has type 'const char *'}}
+ }
+ };
+
+ void use_class(Printer<const char *> &p) {
+ p.print("abc"); // expected-note {{requested here}}
+ }
+
+
+ extern void (^block_print)(const char * format, ...) __attribute__((format(printf, 1, 2)));
+
+ template<typename T>
+ void uninstantiated_call_block_print(const T &arg) {
+ block_print("%d", arg); // no-warning
+ }
+
+ template<typename T>
+ void call_block_print(const T &arg) {
+ block_print("%d", arg); // expected-warning {{format specifies type 'int' but the argument has type 'const char *'}}
+ }
+
+ void use_block_print() {
+ call_block_print("abc"); // expected-note {{requested here}}
+ }
+}
+
OpenPOWER on IntegriCloud