return r;
}
+/* T is an operand of a template tree being substituted. Return whether
+ T is dependent such that we should suppress some warnings that would
+ make sense if the substituted expression were written directly, like
+ template <int I> bool f() { return I == 2; }
+ We don't want to warn when instantiating f that comparing two constants
+ always has the same value.
+
+ This is a more limited concept of dependence than instantiation-dependent;
+ here we don't care whether substitution could fail. */
+
+static bool
+dependent_operand_p (tree t)
+{
+ while (TREE_CODE (t) == IMPLICIT_CONV_EXPR)
+ t = TREE_OPERAND (t, 0);
+ ++processing_template_decl;
+ bool r = (potential_constant_expression (t)
+ ? value_dependent_expression_p (t)
+ : type_dependent_expression_p (t));
+ --processing_template_decl;
+ return r;
+}
+
/* Like tsubst_copy for expressions, etc. but also does semantic
processing. */
IF_STMT_CONSTEVAL_P (stmt) = IF_STMT_CONSTEVAL_P (t);
if (IF_STMT_CONSTEXPR_P (t))
args = add_extra_args (IF_STMT_EXTRA_ARGS (t), args, complain, in_decl);
- tmp = RECUR (IF_COND (t));
- tmp = finish_if_stmt_cond (tmp, stmt);
+ {
+ tree cond = IF_COND (t);
+ bool was_dep = dependent_operand_p (cond);
+ cond = RECUR (cond);
+ warning_sentinel s1(warn_address, was_dep);
+ tmp = finish_if_stmt_cond (cond, stmt);
+ }
if (IF_STMT_CONSTEXPR_P (t)
&& instantiation_dependent_expression_p (tmp))
{
warnings that depend on the range of the types involved. */
tree op0 = TREE_OPERAND (t, 0);
tree op1 = TREE_OPERAND (t, 1);
- auto dep_p = [](tree t) {
- ++processing_template_decl;
- bool r = (potential_constant_expression (t)
- ? value_dependent_expression_p (t)
- : type_dependent_expression_p (t));
- --processing_template_decl;
- return r;
- };
- const bool was_dep = dep_p (op0) || dep_p (op1);
+ const bool was_dep = (dependent_operand_p (op0)
+ || dependent_operand_p (op1));
op0 = RECUR (op0);
op1 = RECUR (op1);
IF_STMT. */
tree
-finish_if_stmt_cond (tree cond, tree if_stmt)
+finish_if_stmt_cond (tree orig_cond, tree if_stmt)
{
- cond = maybe_convert_cond (cond);
+ tree cond = maybe_convert_cond (orig_cond);
if (IF_STMT_CONSTEXPR_P (if_stmt)
&& !type_dependent_expression_p (cond)
&& require_constant_expression (cond)
cond = cxx_constant_value (cond, NULL_TREE);
}
else
- maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false);
+ {
+ maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false);
+ if (processing_template_decl)
+ cond = orig_cond;
+ }
finish_cond (&IF_COND (if_stmt), cond);
add_stmt (if_stmt);
THEN_CLAUSE (if_stmt) = push_stmt_list ();