diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2011-02-20 13:06:31 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2011-02-20 13:06:31 +0000 |
commit | bca07a4524feb4edec581062d631a13116320a24 (patch) | |
tree | a9243275843fbeaa590afc07ee888e006b8d54ea /test/SemaCXX/attr-nonnull.cpp | |
parent | 998bc5802ecdd65ce3b270f6c69a8ae8557f0a10 (diff) |
Notes
Diffstat (limited to 'test/SemaCXX/attr-nonnull.cpp')
-rw-r--r-- | test/SemaCXX/attr-nonnull.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/SemaCXX/attr-nonnull.cpp b/test/SemaCXX/attr-nonnull.cpp new file mode 100644 index 000000000000..19d6642eb553 --- /dev/null +++ b/test/SemaCXX/attr-nonnull.cpp @@ -0,0 +1,29 @@ +// 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); +} + +namespace rdar8769025 { + __attribute__((nonnull)) void f0(int *&p); + __attribute__((nonnull)) void f1(int * const &p); + __attribute__((nonnull(2))) void f2(int i, int * const &p); + + void test_f1() { + f1(0); // expected-warning{{null passed to a callee which requires a non-null argument}} + f2(0, 0); // expected-warning{{null passed to a callee which requires a non-null argument}} + } +} |