From: Jason Merrill Date: Thu, 21 Jul 2016 06:05:39 +0000 (-0400) Subject: PR c++/65168 - -Waddress in unevaluated context. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=451dcc6693e5e489f9f5bf6ba90cedf8f335ad00;p=gcc.git PR c++/65168 - -Waddress in unevaluated context. gcc/c-family/ * c-common.c (c_common_truthvalue_conversion): Check c_inhibit_evaluation_warnings for warning about address of reference. gcc/cp/ * typeck.c (cp_truthvalue_conversion): Compare pointers to nullptr. Don't set c_inhibit_evaluation_warnings. From-SVN: r238560 --- diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 3842929d32c..e244e8aea01 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,10 @@ +2016-07-21 Jason Merrill + + PR c++/65168 + * c-common.c (c_common_truthvalue_conversion): Check + c_inhibit_evaluation_warnings for warning about address of + reference. + 2016-07-20 David Malcolm * c-common.h (lookup_name_fuzzy): Convert return type from tree to diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 936ddfb87e5..9900e93ffc2 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -4551,6 +4551,7 @@ c_common_truthvalue_conversion (location_t location, tree expr) tree fromtype = TREE_TYPE (TREE_OPERAND (expr, 0)); if (POINTER_TYPE_P (totype) + && !c_inhibit_evaluation_warnings && TREE_CODE (fromtype) == REFERENCE_TYPE) { tree inner = expr; diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8ff7f758c99..be223f2c177 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2016-07-21 Jason Merrill + PR c++/65168 + * typeck.c (cp_truthvalue_conversion): Compare pointers to nullptr. + Don't set c_inhibit_evaluation_warnings. + PR c++/71121 * cp-gimplify.c (cp_fully_fold): First call maybe_constant_value. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index f9e45ee125f..d4bfb112a53 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -5459,21 +5459,10 @@ tree cp_truthvalue_conversion (tree expr) { tree type = TREE_TYPE (expr); - if (TYPE_PTRDATAMEM_P (type) + if (TYPE_PTR_OR_PTRMEM_P (type) /* Avoid ICE on invalid use of non-static member function. */ || TREE_CODE (expr) == FUNCTION_DECL) - return build_binary_op (EXPR_LOCATION (expr), - NE_EXPR, expr, nullptr_node, 1); - else if (TYPE_PTR_P (type) || TYPE_PTRMEMFUNC_P (type)) - { - /* With -Wzero-as-null-pointer-constant do not warn for an - 'if (p)' or a 'while (!p)', where p is a pointer. */ - tree ret; - ++c_inhibit_evaluation_warnings; - ret = c_common_truthvalue_conversion (input_location, expr); - --c_inhibit_evaluation_warnings; - return ret; - } + return build_binary_op (input_location, NE_EXPR, expr, nullptr_node, 1); else return c_common_truthvalue_conversion (input_location, expr); } diff --git a/gcc/testsuite/g++.dg/warn/Waddress-3.C b/gcc/testsuite/g++.dg/warn/Waddress-3.C new file mode 100644 index 00000000000..13d7cd2c001 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Waddress-3.C @@ -0,0 +1,14 @@ +// PR c++/65168 +// { dg-do compile { target c++11 } } +// { dg-options -Waddress } +// We shouldn't warn in unevaluated context about the address of a reference +// always being true. + +template +auto f(U&& u) -> decltype(T(u)) { } + +int main() +{ + bool ar[4]; + f(ar); +} diff --git a/gcc/testsuite/g++.dg/warn/Walways-true-1.C b/gcc/testsuite/g++.dg/warn/Walways-true-1.C index ae6f9dc831d..48b9f728bfd 100644 --- a/gcc/testsuite/g++.dg/warn/Walways-true-1.C +++ b/gcc/testsuite/g++.dg/warn/Walways-true-1.C @@ -12,19 +12,19 @@ void bar (int a) { lab: - if (foo) // { dg-warning "always evaluate as" "correct warning" } + if (foo) // { dg-warning "always evaluate as|never be NULL" "correct warning" } foo (0); if (foo (1)) ; - if (&i) // { dg-warning "always evaluate as" "correct warning" } + if (&i) // { dg-warning "always evaluate as|never be NULL" "correct warning" } foo (2); if (i) foo (3); - if (&a) // { dg-warning "always evaluate as" "correct warning" } + if (&a) // { dg-warning "always evaluate as|never be NULL" "correct warning" } foo (4); if (a) foo (5); - if (&&lab) // { dg-warning "always evaluate as" "correct warning" } + if (&&lab) // { dg-warning "always evaluate as|never be NULL" "correct warning" } foo (6); if (foo == 0) // { dg-warning "never be NULL" "correct warning" } foo (7); diff --git a/gcc/testsuite/g++.dg/warn/Walways-true-2.C b/gcc/testsuite/g++.dg/warn/Walways-true-2.C index f1573470ef2..e4b5713c88f 100644 --- a/gcc/testsuite/g++.dg/warn/Walways-true-2.C +++ b/gcc/testsuite/g++.dg/warn/Walways-true-2.C @@ -23,11 +23,11 @@ bar (int a) foo (2); if (i) foo (3); - if (&a) // { dg-warning "always evaluate as" "correct warning" } + if (&a) // { dg-warning "always evaluate as|never be NULL" "correct warning" } foo (4); if (a) foo (5); - if (&&lab) // { dg-warning "always evaluate as" "correct warning" } + if (&&lab) // { dg-warning "always evaluate as|never be NULL" "correct warning" } foo (6); if (foo == 0) foo (7);