+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
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.
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);
}
--- /dev/null
+// 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);
+}
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);
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);