Debian Codegraph @

gcc/testsuite/g++.dg/warn/Wnonnull5.C

raw
1 /* PR c++/86568 - -Wnonnull warnings should highlight the relevant argument
2 not the closing parenthesis.
3 { dg-do compile }
4 { dg-options "-O2 -Wall" } */
5
6 #define NONNULL __attribute__ ((nonnull))
7
8 #if __cplusplus < 201103L
9 # define nullptr __null
10 #endif
11
12 struct S
13 {
14 void
15 f0 (const void*) const; // { dg-message "in a call to non-static member function 'void S::f0\\(const void\\*\\) const'" }
16
17 void
18 f1 (const void*) const; // { dg-message "in a call to non-static member function 'void S::f1\\(const void\\*\\) const'" }
19
20 void
21 f2 (const void*) const; // { dg-message "in a call to non-static member function 'void S::f2\\(const void\\*\\) const'" }
22
23 NONNULL void
24 f3 (const void*, const void*); // { dg-message "in a call to function 'void S::f3\\(const void\\*, const void\\*\\)' declared 'nonnull'" }
25
26 NONNULL void
27 f4 (const void*, const void*); // { dg-message "in a call to function 'void S::f4\\(const void\\*, const void\\*\\)' declared 'nonnull'" }
28
29 NONNULL void
30 f5 (const void*, const void*); // { dg-message "in a call to function 'void S::f5\\\(const void\\*, const void\\*\\)' declared 'nonnull'" }
31
32 NONNULL void
33 f6 (const void*, const void*); // { dg-message "in a call to function 'void S::f6\\\(const void\\*, const void\\*\\)' declared 'nonnull'" }
34 };
35
36 void warn_nullptr_this ()
37 {
38 ((S*)nullptr)->f0 (""); // { dg-warning "3:'this' pointer is null" "pr86568" { xfail *-*-* } }
39 // { dg-warning "this' pointer is null" "pr86568 second variant" { target *-*-* } .-1 }
40 }
41
42 void warn_null_this_cst ()
43 {
44 S* const null = 0;
45 null->f1 (""); // { dg-warning "3:'this' pointer is null" }
46 }
47
48 void warn_null_this_var ()
49 {
50 S* null = 0;
51 null->f2 (&null); // { dg-warning "3:'this' pointer is null" "pr86568" { xfail *-*-* } }
52 // { dg-warning "'this' pointer is null" "pr86568 second variant" { target *-*-* } .-1 }
53 }
54
55 void warn_nullptr (S s)
56 {
57 s.f3 (nullptr, &s); // { dg-warning "9:argument 1 null where non-null expected" "pr86568" { xfail *-*-* } }
58 // { dg-warning "argument 1 null where non-null expected" "pr86568 second variant" { target *-*-* } .-1 }
59 s.f3 (&s, nullptr); // { dg-warning "13:argument 2 null where non-null expected" "pr86568" { xfail *-*-* } }
60 // { dg-warning "argument 2 null where non-null expected" "pr86568 second variant" { target *-*-* } .-1 }
61 }
62
63
64 void warn_null_cst (S s)
65 {
66 void* const null = 0;
67 s.f4 (null, &s); // { dg-warning "9:argument 1 null where non-null expected" }
68 s.f4 (&s, null); // { dg-warning "13:argument 2 null where non-null expected" }
69 }
70
71 void warn_null_var (S s)
72 {
73 void* null = 0;
74 s.f5 (null, &s); // { dg-warning "9:argument 1 null where non-null expected" "pr86568" { xfail *-*-* } }
75 // { dg-warning "argument 1 null where non-null expected" "pr86568 second variant" { target *-*-* } .-1 }
76 s.f5 (&s, null); // { dg-warning "16:argument 2 null where non-null expected" "pr86568" { xfail *-*-* } }
77 // { dg-warning "argument 2 null where non-null expected" "pr86568 second variant" { target *-*-* } .-1 }
78 }
79
80 void warn_null_cond (S s, void *null)
81 {
82 if (null)
83 return;
84
85 s.f6 (null, &s); // { dg-warning "9:argument 1 null where non-null expected" "pr86568" { xfail *-*-* } }
86 // { dg-warning "argument 1 null where non-null expected" "pr86568 second variant" { target *-*-* } .-1 }
87 s.f6 (&s, null); // { dg-warning "13:argument 2 null where non-null expected" "pr86568" { xfail *-*-* } }
88 // { dg-warning "argument 2 null where non-null expected" "pr86568 second variant" { target *-*-* } .-1 }
89 }
90
91
92 typedef NONNULL void Fvp (const void*, const void*);
93
94 void warn_fptr_null_cst (Fvp *p)
95 {
96 void* const null = 0;
97 p (null, ""); // { dg-warning "6:argument 1 null where non-null expected" }
98 p ("", null); // { dg-warning "10:argument 2 null where non-null expected" }
99 }
100
101 typedef NONNULL void (S::*SMemFvp) (const void*, const void*);
102
103 void warn_memfptr_null_cst (S *p, SMemFvp pmf)
104 {
105 void* const null = 0;
106 (p->*pmf) (null, ""); // { dg-warning "14:argument 1 null where non-null expected" }
107 (p->*pmf) ("", null); // { dg-warning "18:argument 2 null where non-null expected" }
108 }