summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/SemaCXX/attr-format.cpp15
-rw-r--r--clang/test/SemaCXX/attr-nonnull.cpp18
-rw-r--r--clang/test/SemaCXX/format-attribute.cpp8
3 files changed, 33 insertions, 8 deletions
diff --git a/clang/test/SemaCXX/attr-format.cpp b/clang/test/SemaCXX/attr-format.cpp
index 0c1eb53ea07..bf131496007 100644
--- a/clang/test/SemaCXX/attr-format.cpp
+++ b/clang/test/SemaCXX/attr-format.cpp
@@ -1,8 +1,23 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
struct S {
static void f(const char*, ...) __attribute__((format(printf, 1, 2)));
+ static const char* f2(const char*) __attribute__((format_arg(1)));
// GCC has a hidden 'this' argument in member functions which is why
// the format argument is argument 2 here.
void g(const char*, ...) __attribute__((format(printf, 2, 3)));
+ const char* g2(const char*) __attribute__((format_arg(2)));
+
+ void h(const char*, ...) __attribute__((format(printf, 1, 4))); // \
+ expected-error{{implicit this argument as the format string}}
+ void h2(const char*, ...) __attribute__((format(printf, 2, 1))); // \
+ expected-error{{out of bounds}}
+ const char* h3(const char*) __attribute__((format_arg(1))); // \
+ expected-error{{invalid for the implicit this argument}}
};
+
+// PR5521
+struct A { void a(const char*,...) __attribute((format(printf,2,3))); };
+void b(A x) {
+ x.a("%d", 3);
+}
diff --git a/clang/test/SemaCXX/attr-nonnull.cpp b/clang/test/SemaCXX/attr-nonnull.cpp
new file mode 100644
index 00000000000..e5b5329ffca
--- /dev/null
+++ b/clang/test/SemaCXX/attr-nonnull.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+struct S {
+ static void f(const char*, const char*) __attribute__((nonnull(1)));
+
+ // GCC has a hidden 'this' argument in member functions, so the middle
+ // argument is the one that must not be null.
+ void g(const char*, const char*, const char*) __attribute__((nonnull(3)));
+
+ void h(const char*) __attribute__((nonnull(1))); // \
+ expected-error{{invalid for the implicit this argument}}
+};
+
+void test(S s) {
+ s.f(0, ""); // expected-warning{{null passed}}
+ s.f("", 0);
+ s.g("", 0, ""); // expected-warning{{null passed}}
+ s.g(0, "", 0);
+}
diff --git a/clang/test/SemaCXX/format-attribute.cpp b/clang/test/SemaCXX/format-attribute.cpp
deleted file mode 100644
index 92b7cf517ef..00000000000
--- a/clang/test/SemaCXX/format-attribute.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
-
-// PR5521
-struct A { void a(const char*,...) __attribute((format(printf,2,3))); };
-void b(A x) {
- x.a("%d", 3);
-}
-struct X { void a(const char*,...) __attribute((format(printf,1,3))); }; // expected-error {{format argument not a string type}}
OpenPOWER on IntegriCloud