1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2f4a2713aSLionel Sambuc struct S {
3f4a2713aSLionel Sambuc S(const char *) __attribute__((nonnull(2)));
4f4a2713aSLionel Sambuc
5f4a2713aSLionel Sambuc static void f(const char*, const char*) __attribute__((nonnull(1)));
6f4a2713aSLionel Sambuc
7f4a2713aSLionel Sambuc // GCC has a hidden 'this' argument in member functions, so the middle
8f4a2713aSLionel Sambuc // argument is the one that must not be null.
9f4a2713aSLionel Sambuc void g(const char*, const char*, const char*) __attribute__((nonnull(3)));
10f4a2713aSLionel Sambuc
11f4a2713aSLionel Sambuc void h(const char*) __attribute__((nonnull(1))); // \
12f4a2713aSLionel Sambuc expected-error{{invalid for the implicit this argument}}
13f4a2713aSLionel Sambuc };
14f4a2713aSLionel Sambuc
test()15f4a2713aSLionel Sambuc void test() {
16f4a2713aSLionel Sambuc S s(0); // expected-warning{{null passed}}
17f4a2713aSLionel Sambuc
18f4a2713aSLionel Sambuc s.f(0, ""); // expected-warning{{null passed}}
19f4a2713aSLionel Sambuc s.f("", 0);
20f4a2713aSLionel Sambuc s.g("", 0, ""); // expected-warning{{null passed}}
21f4a2713aSLionel Sambuc s.g(0, "", 0);
22f4a2713aSLionel Sambuc }
23f4a2713aSLionel Sambuc
24f4a2713aSLionel Sambuc namespace rdar8769025 {
25f4a2713aSLionel Sambuc __attribute__((nonnull)) void f0(int *&p);
26f4a2713aSLionel Sambuc __attribute__((nonnull)) void f1(int * const &p);
27f4a2713aSLionel Sambuc __attribute__((nonnull(2))) void f2(int i, int * const &p);
28f4a2713aSLionel Sambuc
test_f1()29f4a2713aSLionel Sambuc void test_f1() {
30*0a6a1f1dSLionel Sambuc f1(0); // expected-warning{{null passed to a callee that requires a non-null argument}}
31*0a6a1f1dSLionel Sambuc f2(0, 0); // expected-warning{{null passed to a callee that requires a non-null argument}}
32f4a2713aSLionel Sambuc }
33f4a2713aSLionel Sambuc }
34f4a2713aSLionel Sambuc
35f4a2713aSLionel Sambuc namespace test3 {
36f4a2713aSLionel Sambuc __attribute__((nonnull(1))) void f(void *ptr);
37f4a2713aSLionel Sambuc
g()38f4a2713aSLionel Sambuc void g() {
39f4a2713aSLionel Sambuc f(static_cast<char*>((void*)0)); // expected-warning{{null passed}}
40f4a2713aSLionel Sambuc f(static_cast<char*>(0)); // expected-warning{{null passed}}
41f4a2713aSLionel Sambuc }
42f4a2713aSLionel Sambuc }
43f4a2713aSLionel Sambuc
44f4a2713aSLionel Sambuc namespace test4 {
45f4a2713aSLionel Sambuc struct X {
46f4a2713aSLionel Sambuc bool operator!=(const void *) const __attribute__((nonnull(2)));
47f4a2713aSLionel Sambuc };
48f4a2713aSLionel Sambuc bool operator==(const X&, const void *) __attribute__((nonnull(2)));
49f4a2713aSLionel Sambuc
test(const X & x)50f4a2713aSLionel Sambuc void test(const X& x) {
51f4a2713aSLionel Sambuc (void)(x == 0); // expected-warning{{null passed}}
52f4a2713aSLionel Sambuc (void)(x != 0); // expected-warning{{null passed}}
53f4a2713aSLionel Sambuc }
54f4a2713aSLionel Sambuc }
55