1 /* PR c/102103 - missing warning comparing array address to null
3 { dg-options "-Wall" } */
5 #if __cplusplus < 201103L
6 # define nullptr __null
13 virtual void pvf () = 0;
23 void warn_memptr_if ()
25 // Exercise warnings for addresses of nonstatic member functions.
26 // On targets with TARGET_PTRMEMFUNC_VBIT_LOCATION ==
27 // ptrmemfunc_vbit_in_delta, cp_build_binary_op recurses to compare
28 // the pfn from the ptrmemfunc with null, so we get two warnings.
29 // This matches both. ??? Should we disable one of them?
30 if (&A::f == 0) // { dg-warning "A::f" }
33 if (&A::vf) // { dg-warning "-Waddress" }
36 if (&A::pvf != 0) // { dg-warning "-Waddress" }
39 // Exercise warnings for addresses of static member functions.
40 if (&A::sf == 0) // { dg-warning "-Waddress" }
43 if (&A::sf) // { dg-warning "-Waddress" }
46 // Exercise warnings for addresses of nonstatic data members.
47 if (&A::p == 0) // { dg-warning "the address '&A::p'" }
50 if (&A::a == nullptr) // { dg-warning "-Waddress" }
54 void warn_memptr_bool ()
56 // Exercise warnings for addresses of nonstatic member functions.
57 T (&A::f == 0); // { dg-warning "-Waddress" }
58 T (&A::vf); // { dg-warning "-Waddress" }
59 T (&A::pvf != 0); // { dg-warning "-Waddress" }
61 // Exercise warnings for addresses of static member functions.
62 T (&A::sf == 0); // { dg-warning "-Waddress" }
63 T (&A::sf); // { dg-warning "-Waddress" }
65 // Exercise warnings for addresses of nonstatic data members.
66 T (&A::p == 0); // { dg-warning "-Waddress" }
67 T (&A::a == nullptr); // { dg-warning "-Waddress" }
71 /* Verify that no warnings are issued for a dependent expression in
78 struct F { void* operator& () const { return 0; } } f;
81 template <class Type, int N>
82 void nowarn_dependent (Type targ)
88 T (&tarr[0] == nullptr);
92 /* Like in the case above, the address-of operator could be a member
93 of B<N>::vf that returns zero. */
101 /* Verify that in an uninstantiated template warnings are not issued
102 for dependent expressions but are issued otherwise. */
104 template <class Type>
105 void warn_non_dependent (Type targ, Type *tptr, int i)
107 /* The address of a pointer to a dependent type cannot be null but
108 the warning doesn't have a chance to see it. */
109 T (&tptr == 0); // { dg-warning "-Waddress" "pr102378" { xfail *-*-* } }
110 T (&i == 0); // { dg-warning "-Waddress" }
113 T (&iarr == 0); // { dg-warning "-Waddress" }
114 T (&*iarr != 0); // { dg-warning "-Waddress" "pr102378" { xfail *-*-* } }
115 T (&iarr[0] == 0); // { dg-warning "-Waddress" }
118 T (&tarr == nullptr); // { dg-warning "-Waddress" "pr102378" { xfail *-*-* } }