Commit 4dd468a0 by Jason Merrill

c++: Fix -Wtype-limits in templates.

When instantiating a template tsubst_copy_and_build suppresses -Wtype-limits
warnings about e.g. == always being false because it might not always be
false for an instantiation with other template arguments.  But we should
warn if the operands don't depend on template arguments.

	PR c++/82521
	* pt.c (tsubst_copy_and_build) [EQ_EXPR]: Only suppress warnings if
	the expression was dependent before substitution.
parent 004ac7b7
2020-01-29 Jason Merrill <jason@redhat.com>
PR c++/82521
* pt.c (tsubst_copy_and_build) [EQ_EXPR]: Only suppress warnings if
the expression was dependent before substitution.
2020-01-30 Bin Cheng <bin.cheng@linux.alibaba.com> 2020-01-30 Bin Cheng <bin.cheng@linux.alibaba.com>
* coroutines.cc (act_des_fn): New. * coroutines.cc (act_des_fn): New.
......
...@@ -19279,10 +19279,14 @@ tsubst_copy_and_build (tree t, ...@@ -19279,10 +19279,14 @@ tsubst_copy_and_build (tree t,
case MEMBER_REF: case MEMBER_REF:
case DOTSTAR_EXPR: case DOTSTAR_EXPR:
{ {
warning_sentinel s1(warn_type_limits); /* If T was type-dependent, suppress warnings that depend on the range
warning_sentinel s2(warn_div_by_zero); of the types involved. */
warning_sentinel s3(warn_logical_op); bool was_dep = uses_template_parms (t);
warning_sentinel s4(warn_tautological_compare); warning_sentinel s1(warn_type_limits, was_dep);
warning_sentinel s2(warn_div_by_zero, was_dep);
warning_sentinel s3(warn_logical_op, was_dep);
warning_sentinel s4(warn_tautological_compare, was_dep);
tree op0 = RECUR (TREE_OPERAND (t, 0)); tree op0 = RECUR (TREE_OPERAND (t, 0));
tree op1 = RECUR (TREE_OPERAND (t, 1)); tree op1 = RECUR (TREE_OPERAND (t, 1));
tree r = build_x_binary_op tree r = build_x_binary_op
......
// PR c++/82521
// { dg-additional-options "-Wtype-limits" }
template <typename T>
const char * g(const unsigned char value)
{
return value == -1 ? "-1" : "no"; // { dg-warning "always false" }
}
int main()
{
g<int>(-1);
}
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