summaryrefslogtreecommitdiffstats
path: root/test/SemaCXX/attr-nonnull.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2010-11-16 08:35:43 +0000
committerChandler Carruth <chandlerc@gmail.com>2010-11-16 08:35:43 +0000
commit07d7e7a6b10f798459f350b792713db2fb3e9365 (patch)
tree83eda576796ee47783debbb085a00f8105c091c1 /test/SemaCXX/attr-nonnull.cpp
parentf019943eda4896c1bbe584b4b0439bf6cbff62a9 (diff)
Re-work the handling of implicit 'this' arguments and silly GCC-style attribute
argument indexes. This handles the offsets in a consistent manner for all of the attributes which I saw working with these concepts. I've also added tests for the attribute that motivated this: nonnull. I consolidated the tests for format attributes into one file, and fleshed them out a bit to trigger more of the warning cases. Also improved the quality of some of the diagnostics that occur with invalid argument indices. The only really questionable change here is supporting the implicit this argument for the ownership attribute. I'm not sure it's really a sensible concept there, but implemented the logic for consistency. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119339 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/attr-nonnull.cpp')
-rw-r--r--test/SemaCXX/attr-nonnull.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/SemaCXX/attr-nonnull.cpp b/test/SemaCXX/attr-nonnull.cpp
new file mode 100644
index 0000000000..e5b5329ffc
--- /dev/null
+++ b/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);
+}