Commit 451dcc66 by Jason Merrill Committed by Jason Merrill

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
parent e96fe88c
2016-07-21 Jason Merrill <jason@redhat.com>
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 <dmalcolm@redhat.com>
* c-common.h (lookup_name_fuzzy): Convert return type from tree to
......
......@@ -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;
......
2016-07-21 Jason Merrill <jason@redhat.com>
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.
......
......@@ -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);
}
......
// 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 <class T, class U>
auto f(U&& u) -> decltype(T(u)) { }
int main()
{
bool ar[4];
f<bool>(ar);
}
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment