Commit 2ab340fe by Paolo Carlini Committed by Paolo Carlini

typeck.c (cp_truthvalue_conversion): Add tsubst_flags_t parameter and use it in calls...

/cp
2019-11-15  Paolo Carlini  <paolo.carlini@oracle.com>

	* typeck.c (cp_truthvalue_conversion): Add tsubst_flags_t parameter
	and use it in calls; also pass the location_t of the expression to
	cp_build_binary_op and c_common_truthvalue_conversion.
	* rtti.c (build_dynamic_cast_1): Adjust call.
	* cvt.c (ocp_convert): Likewise.
	* cp-gimplify.c (cp_fold): Likewise.
	* cp-tree.h (cp_truthvalue_conversion): Update declaration.

/testsuite
2019-11-15  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/warn/Walways-true-1.C: Check locations too.
	* g++.dg/warn/Walways-true-2.C: Likewise.
	* g++.dg/warn/Walways-true-3.C: Likewise.
	* g++.dg/warn/Waddress-1.C: Check additional location.

From-SVN: r278320
parent f982d12a
2019-11-15 Paolo Carlini <paolo.carlini@oracle.com>
* typeck.c (cp_truthvalue_conversion): Add tsubst_flags_t parameter
and use it in calls; also pass the location_t of the expression to
cp_build_binary_op and c_common_truthvalue_conversion.
* rtti.c (build_dynamic_cast_1): Adjust call.
* cvt.c (ocp_convert): Likewise.
* cp-gimplify.c (cp_fold): Likewise.
* cp-tree.h (cp_truthvalue_conversion): Update declaration.
2019-11-14 Jason Merrill <jason@redhat.com> 2019-11-14 Jason Merrill <jason@redhat.com>
Implement P1816R0, class template argument deduction for aggregates. Implement P1816R0, class template argument deduction for aggregates.
......
...@@ -2573,9 +2573,9 @@ cp_fold (tree x) ...@@ -2573,9 +2573,9 @@ cp_fold (tree x)
{ {
warning_sentinel s (warn_int_in_bool_context); warning_sentinel s (warn_int_in_bool_context);
if (!VOID_TYPE_P (TREE_TYPE (op1))) if (!VOID_TYPE_P (TREE_TYPE (op1)))
op1 = cp_truthvalue_conversion (op1); op1 = cp_truthvalue_conversion (op1, tf_warning_or_error);
if (!VOID_TYPE_P (TREE_TYPE (op2))) if (!VOID_TYPE_P (TREE_TYPE (op2)))
op2 = cp_truthvalue_conversion (op2); op2 = cp_truthvalue_conversion (op2, tf_warning_or_error);
} }
else if (VOID_TYPE_P (TREE_TYPE (x))) else if (VOID_TYPE_P (TREE_TYPE (x)))
{ {
......
...@@ -7450,7 +7450,7 @@ enum compare_bounds_t { bounds_none, bounds_either, bounds_first }; ...@@ -7450,7 +7450,7 @@ enum compare_bounds_t { bounds_none, bounds_either, bounds_first };
extern bool cxx_mark_addressable (tree, bool = false); extern bool cxx_mark_addressable (tree, bool = false);
extern int string_conv_p (const_tree, const_tree, int); extern int string_conv_p (const_tree, const_tree, int);
extern tree cp_truthvalue_conversion (tree); extern tree cp_truthvalue_conversion (tree, tsubst_flags_t);
extern tree contextual_conv_bool (tree, tsubst_flags_t); extern tree contextual_conv_bool (tree, tsubst_flags_t);
extern tree condition_conversion (tree); extern tree condition_conversion (tree);
extern tree require_complete_type (tree); extern tree require_complete_type (tree);
......
...@@ -841,13 +841,13 @@ ocp_convert (tree type, tree expr, int convtype, int flags, ...@@ -841,13 +841,13 @@ ocp_convert (tree type, tree expr, int convtype, int flags,
if (SCOPED_ENUM_P (intype) && (convtype & CONV_STATIC)) if (SCOPED_ENUM_P (intype) && (convtype & CONV_STATIC))
e = build_nop (ENUM_UNDERLYING_TYPE (intype), e); e = build_nop (ENUM_UNDERLYING_TYPE (intype), e);
if (complain & tf_warning) if (complain & tf_warning)
return cp_truthvalue_conversion (e); return cp_truthvalue_conversion (e, complain);
else else
{ {
/* Prevent bogus -Wint-in-bool-context warnings coming /* Prevent bogus -Wint-in-bool-context warnings coming
from c_common_truthvalue_conversion down the line. */ from c_common_truthvalue_conversion down the line. */
warning_sentinel w (warn_int_in_bool_context); warning_sentinel w (warn_int_in_bool_context);
return cp_truthvalue_conversion (e); return cp_truthvalue_conversion (e, complain);
} }
} }
......
...@@ -782,7 +782,7 @@ build_dynamic_cast_1 (tree type, tree expr, tsubst_flags_t complain) ...@@ -782,7 +782,7 @@ build_dynamic_cast_1 (tree type, tree expr, tsubst_flags_t complain)
tree neq; tree neq;
result = save_expr (result); result = save_expr (result);
neq = cp_truthvalue_conversion (result); neq = cp_truthvalue_conversion (result, complain);
return cp_convert (type, return cp_convert (type,
build3 (COND_EXPR, TREE_TYPE (result), build3 (COND_EXPR, TREE_TYPE (result),
neq, result, bad), complain); neq, result, bad), complain);
......
...@@ -5981,15 +5981,16 @@ cp_build_addressof (location_t loc, tree arg, tsubst_flags_t complain) ...@@ -5981,15 +5981,16 @@ cp_build_addressof (location_t loc, tree arg, tsubst_flags_t complain)
-1. */ -1. */
tree tree
cp_truthvalue_conversion (tree expr) cp_truthvalue_conversion (tree expr, tsubst_flags_t complain)
{ {
tree type = TREE_TYPE (expr); tree type = TREE_TYPE (expr);
location_t loc = cp_expr_loc_or_input_loc (expr);
if (TYPE_PTR_OR_PTRMEM_P (type) if (TYPE_PTR_OR_PTRMEM_P (type)
/* Avoid ICE on invalid use of non-static member function. */ /* Avoid ICE on invalid use of non-static member function. */
|| TREE_CODE (expr) == FUNCTION_DECL) || TREE_CODE (expr) == FUNCTION_DECL)
return build_binary_op (input_location, NE_EXPR, expr, nullptr_node, true); return cp_build_binary_op (loc, NE_EXPR, expr, nullptr_node, complain);
else else
return c_common_truthvalue_conversion (input_location, expr); return c_common_truthvalue_conversion (loc, expr);
} }
/* Returns EXPR contextually converted to bool. */ /* Returns EXPR contextually converted to bool. */
......
2019-11-15 Paolo Carlini <paolo.carlini@oracle.com>
* g++.dg/warn/Walways-true-1.C: Check locations too.
* g++.dg/warn/Walways-true-2.C: Likewise.
* g++.dg/warn/Walways-true-3.C: Likewise.
* g++.dg/warn/Waddress-1.C: Check additional location.
2019-11-15 Joseph Myers <joseph@codesourcery.com> 2019-11-15 Joseph Myers <joseph@codesourcery.com>
* gcc.dg/c2x-attr-maybe_unused-1.c, * gcc.dg/c2x-attr-maybe_unused-1.c,
......
...@@ -13,7 +13,7 @@ S s; ...@@ -13,7 +13,7 @@ S s;
T t; T t;
double d; double d;
void f() { if (z) z(); } // { dg-warning "address" } void f() { if (z) z(); } // { dg-warning "17:address" }
void gl() { if (z != 0) z(); } // { dg-warning "19:address" } void gl() { if (z != 0) z(); } // { dg-warning "19:address" }
void hl() { if (z != (ptrf)0) z(); } // { dg-warning "19:address" } void hl() { if (z != (ptrf)0) z(); } // { dg-warning "19:address" }
......
...@@ -12,46 +12,46 @@ void ...@@ -12,46 +12,46 @@ void
bar (int a) bar (int a)
{ {
lab: lab:
if (foo) // { dg-warning "always evaluate as|never be NULL" "correct warning" } if (foo) // { dg-warning "7:the address of .int foo\\(int\\). will never be NULL" "correct warning" }
foo (0); foo (0);
if (foo (1)) if (foo (1))
; ;
if (&i) // { dg-warning "always evaluate as|never be NULL" "correct warning" } if (&i) // { dg-warning "7:the address of .i. will never be NULL" "correct warning" }
foo (2); foo (2);
if (i) if (i)
foo (3); foo (3);
if (&a) // { dg-warning "always evaluate as|never be NULL" "correct warning" } if (&a) // { dg-warning "7:the address of .a. will never be NULL" "correct warning" }
foo (4); foo (4);
if (a) if (a)
foo (5); foo (5);
if (&&lab) // { dg-warning "always evaluate as|never be NULL" "correct warning" } if (&&lab) // { dg-warning "7:the address of .lab. will never be NULL" "correct warning" }
foo (6); foo (6);
if (foo == 0) // { dg-warning "never be NULL" "correct warning" } if (foo == 0) // { dg-warning "11:the address of .int foo\\(int\\). will never be NULL" "correct warning" }
foo (7); foo (7);
if (foo (1) == 0) if (foo (1) == 0)
foo (8); foo (8);
if (&i == 0) // { dg-warning "never be NULL" "correct warning" } if (&i == 0) // { dg-warning "10:the address of .i. will never be NULL" "correct warning" }
foo (9); foo (9);
if (i == 0) if (i == 0)
foo (10); foo (10);
if (&a == 0) // { dg-warning "never be NULL" "correct warning" } if (&a == 0) // { dg-warning "10:the address of .a. will never be NULL" "correct warning" }
foo (11); foo (11);
if (a == 0) if (a == 0)
foo (12); foo (12);
if (&&lab == 0) // { dg-warning "never be NULL" "correct warning" } if (&&lab == 0) // { dg-warning "13:the address of .lab. will never be NULL" "correct warning" }
foo (13); foo (13);
if (0 == foo) // { dg-warning "never be NULL" "correct warning" } if (0 == foo) // { dg-warning "9:the address of .int foo\\(int\\). will never be NULL" "correct warning" }
foo (14); foo (14);
if (0 == foo (1)) if (0 == foo (1))
foo (15); foo (15);
if (0 == &i) // { dg-warning "never be NULL" "correct warning" } if (0 == &i) // { dg-warning "9:the address of .i. will never be NULL" "correct warning" }
foo (16); foo (16);
if (0 == i) if (0 == i)
foo (17); foo (17);
if (0 == &a) // { dg-warning "never be NULL" "correct warning" } if (0 == &a) // { dg-warning "9:the address of .a. will never be NULL" "correct warning" }
foo (18); foo (18);
if (0 == a) if (0 == a)
foo (19); foo (19);
if (0 == &&lab) // { dg-warning "never be NULL" "correct warning" } if (0 == &&lab) // { dg-warning "9:the address of .lab. will never be NULL" "correct warning" }
foo (20); foo (20);
} }
...@@ -23,11 +23,11 @@ bar (int a) ...@@ -23,11 +23,11 @@ bar (int a)
foo (2); foo (2);
if (i) if (i)
foo (3); foo (3);
if (&a) // { dg-warning "always evaluate as|never be NULL" "correct warning" } if (&a) // { dg-warning "7:the address of .a. will never be NULL" "correct warning" }
foo (4); foo (4);
if (a) if (a)
foo (5); foo (5);
if (&&lab) // { dg-warning "always evaluate as|never be NULL" "correct warning" } if (&&lab) // { dg-warning "7:the address of .lab. will never be NULL" "correct warning" }
foo (6); foo (6);
if (foo == 0) if (foo == 0)
foo (7); foo (7);
...@@ -37,11 +37,11 @@ bar (int a) ...@@ -37,11 +37,11 @@ bar (int a)
foo (9); foo (9);
if (i == 0) if (i == 0)
foo (10); foo (10);
if (&a == 0) // { dg-warning "never be NULL" "correct warning" } if (&a == 0) // { dg-warning "10:the address of .a. will never be NULL" "correct warning" }
foo (11); foo (11);
if (a == 0) if (a == 0)
foo (12); foo (12);
if (&&lab == 0) // { dg-warning "never be NULL" "correct warning" } if (&&lab == 0) // { dg-warning "13:the address of .lab. will never be NULL" "correct warning" }
foo (13); foo (13);
if (0 == foo) if (0 == foo)
foo (14); foo (14);
...@@ -51,10 +51,10 @@ bar (int a) ...@@ -51,10 +51,10 @@ bar (int a)
foo (16); foo (16);
if (0 == i) if (0 == i)
foo (17); foo (17);
if (0 == &a) // { dg-warning "never be NULL" "correct warning" } if (0 == &a) // { dg-warning "9:the address of .a. will never be NULL" "correct warning" }
foo (18); foo (18);
if (0 == a) if (0 == a)
foo (19); foo (19);
if (0 == &&lab) // { dg-warning "never be NULL" "correct warning" } if (0 == &&lab) // { dg-warning "9:the address of .lab. will never be NULL" "correct warning" }
foo (20); foo (20);
} }
...@@ -11,28 +11,28 @@ bar (int &a) ...@@ -11,28 +11,28 @@ bar (int &a)
{ {
int &b = a; int &b = a;
if ((int *)&a) // { dg-warning "address of" } if ((int *)&a) // { dg-warning "7:the compiler can assume that the address of" }
foo (); foo ();
if (&b) // { dg-warning "address of" } if (&b) // { dg-warning "7:the compiler can assume that the address of" }
foo (); foo ();
if (!&c) // { dg-warning "address of" } if (!&c) // { dg-warning "8:the compiler can assume that the address of" }
foo (); foo ();
if (!&(int &)(int &)a) // { dg-warning "address of" } if (!&(int &)(int &)a) // { dg-warning "8:the compiler can assume that the address of" }
foo (); foo ();
if (&a == 0) // { dg-warning "never be NULL" } if (&a == 0) // { dg-warning "10:the compiler can assume that the address of" }
foo (); foo ();
if (&b != 0) // { dg-warning "never be NULL" } if (&b != 0) // { dg-warning "10:the compiler can assume that the address of" }
foo (); foo ();
if (0 == &(int &)(int &)c) // { dg-warning "never be NULL" } if (0 == &(int &)(int &)c) // { dg-warning "9:the compiler can assume that the address of" }
foo (); foo ();
if (&a != (int *)0) // { dg-warning "never be NULL" } if (&a != (int *)0) // { dg-warning "10:the compiler can assume that the address of" }
foo (); foo ();
} }
...@@ -40,7 +40,7 @@ bool ...@@ -40,7 +40,7 @@ bool
bar_1 (int &a) bar_1 (int &a)
{ {
if (d == 5) if (d == 5)
return &a; // { dg-warning "address of" } return &a; // { dg-warning "12:the compiler can assume that the address of" }
else else
return !&(int &)(int &)a; // { dg-warning "address of" } return !&(int &)(int &)a; // { dg-warning "13:the compiler can assume that the address of" }
} }
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