Révision | 6263dde1ca1907900babb51a45761ababb793def (tree) |
---|---|
l'heure | 2016-02-20 01:02:51 |
Auteur | jakub <jakub@138b...> |
Commiter | jakub |
PR c++/69850
* init.c (build_vec_delete_1): Set TREE_NO_WARNING on the NE_EXPR
condition.
* cp-gimplify.c (cp_fold): Propagate TREE_NO_WARNING from binary
operators if folding preserved the binop, just with different
arguments.
* g++.dg/warn/Wnonnull-compare-2.C: New test.
* g++.dg/warn/Wnonnull-compare-3.C: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@233561 138bc75d-0d04-0410-961f-82ee72b054a4
@@ -1,5 +1,12 @@ | ||
1 | 1 | 2016-02-19 Jakub Jelinek <jakub@redhat.com> |
2 | 2 | |
3 | + PR c++/69850 | |
4 | + * init.c (build_vec_delete_1): Set TREE_NO_WARNING on the NE_EXPR | |
5 | + condition. | |
6 | + * cp-gimplify.c (cp_fold): Propagate TREE_NO_WARNING from binary | |
7 | + operators if folding preserved the binop, just with different | |
8 | + arguments. | |
9 | + | |
3 | 10 | PR c++/67767 |
4 | 11 | * parser.c (cp_parser_std_attribute_spec_seq): Don't assume |
5 | 12 | attr_spec is always single element chain, chain all the attributes |
@@ -2068,6 +2068,9 @@ cp_fold (tree x) | ||
2068 | 2068 | else |
2069 | 2069 | x = fold (x); |
2070 | 2070 | |
2071 | + if (TREE_NO_WARNING (org_x) | |
2072 | + && TREE_CODE (x) == TREE_CODE (org_x)) | |
2073 | + TREE_NO_WARNING (x) = 1; | |
2071 | 2074 | break; |
2072 | 2075 | |
2073 | 2076 | case VEC_COND_EXPR: |
@@ -3678,12 +3678,15 @@ build_vec_delete_1 (tree base, tree maxindex, tree type, | ||
3678 | 3678 | body = integer_zero_node; |
3679 | 3679 | |
3680 | 3680 | /* Outermost wrapper: If pointer is null, punt. */ |
3681 | + tree cond | |
3682 | + = fold_build2_loc (input_location, NE_EXPR, boolean_type_node, base, | |
3683 | + fold_convert (TREE_TYPE (base), nullptr_node)); | |
3684 | + /* This is a compiler generated comparison, don't emit | |
3685 | + e.g. -Wnonnull-compare warning for it. */ | |
3686 | + if (TREE_CODE (cond) == NE_EXPR) | |
3687 | + TREE_NO_WARNING (cond) = 1; | |
3681 | 3688 | body = fold_build3_loc (input_location, COND_EXPR, void_type_node, |
3682 | - fold_build2_loc (input_location, | |
3683 | - NE_EXPR, boolean_type_node, base, | |
3684 | - fold_convert (TREE_TYPE (base), | |
3685 | - nullptr_node)), | |
3686 | - body, integer_zero_node); | |
3689 | + cond, body, integer_zero_node); | |
3687 | 3690 | body = build1 (NOP_EXPR, void_type_node, body); |
3688 | 3691 | |
3689 | 3692 | if (controller) |
@@ -1,5 +1,9 @@ | ||
1 | 1 | 2016-02-19 Jakub Jelinek <jakub@redhat.com> |
2 | 2 | |
3 | + PR c++/69850 | |
4 | + * g++.dg/warn/Wnonnull-compare-2.C: New test. | |
5 | + * g++.dg/warn/Wnonnull-compare-3.C: New test. | |
6 | + | |
3 | 7 | PR c++/67767 |
4 | 8 | * g++.dg/cpp0x/pr67767.C: New test. |
5 | 9 |
@@ -0,0 +1,27 @@ | ||
1 | +// PR c++/69850 | |
2 | +// { dg-do compile } | |
3 | +// { dg-options "-Wnonnull-compare" } | |
4 | + | |
5 | +struct D { | |
6 | + virtual ~D (); | |
7 | + void foo () const { delete this; } // { dg-bogus "nonnull argument" } | |
8 | + template <typename> friend struct A; | |
9 | +}; | |
10 | +template <typename T> struct A { | |
11 | + static void bar (T *x) { x->foo (); } | |
12 | +}; | |
13 | +template <typename T> struct B { | |
14 | + T b; | |
15 | + void baz () { A<T>::bar (&b); } | |
16 | +}; | |
17 | +class C { | |
18 | + class E : public D { ~E (); }; | |
19 | + void baz (); | |
20 | + B<E> c; | |
21 | +}; | |
22 | + | |
23 | +void | |
24 | +C::baz () | |
25 | +{ | |
26 | + c.baz (); | |
27 | +} |
@@ -0,0 +1,28 @@ | ||
1 | +// PR c++/69850 | |
2 | +// { dg-do compile } | |
3 | +// { dg-options "-Wnonnull-compare" } | |
4 | + | |
5 | +template <typename T> | |
6 | +struct A { | |
7 | + static void foo (T *x) { x->bar (); } | |
8 | +}; | |
9 | +template <typename T> | |
10 | +struct B { | |
11 | + T b; | |
12 | + void operator= (B) { A<T>::foo (&b); } | |
13 | +}; | |
14 | +struct C { | |
15 | + void bar () { delete[] this; } // { dg-bogus "nonnull argument" } | |
16 | +}; | |
17 | +struct D { B<C> d; }; | |
18 | +struct G { | |
19 | + D g[6]; | |
20 | + void baz (); | |
21 | +}; | |
22 | +int a; | |
23 | + | |
24 | +void | |
25 | +G::baz () | |
26 | +{ | |
27 | + g[a] = g[1]; | |
28 | +} |