https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105035

--- Comment #7 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Patrick Palka from comment #6)
> (In reply to Jakub Jelinek from comment #3)
> > Another option is to make sure we don't call 
> > warn_duplicated_cond_add_or_warn
> > when processing_template_decl or say when value_dependent_expression_p or
> > similar, and instead call it during template instantiation in pt.cc after
> > finish_if_stmt_cond call there.
> 
> I noticed the warning already gives up on conditions that have
> TREE_SIDE_EFFECTS set, so I suppose it makes sense to do the same for
> type-dependent expressions since we can't know if they have side effects
> until instantiation time.

However, doing the check at instantiation time for dependent conditions might
be problematic since two different dependent conditions could instantiate to
the same non-dependent condition, and I don't think we'd want to issue a
-Wduplicated-cond warning in this case.  For example,

template<class T, class U>
void f() {
  if (T() == 5)
    ...
  else if (U() == 5)
    ...
}

I'm not sure issuing a warning at instantiation time for f<int, int>() would be
appropriate.  We'd might have to compare the dependent conditions even at
instantiation time, provided that the instantiated condition doesn't have
TREE_SIDE_EFFECTS set...  Seems quite messy to get right.

Reply via email to