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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpola...@gcc.gnu.org>:

https://gcc.gnu.org/g:623730d954a051941ae6a098f851bef308916ca0

commit r13-5582-g623730d954a051941ae6a098f851bef308916ca0
Author: Marek Polacek <pola...@redhat.com>
Date:   Thu Jan 26 09:34:28 2023 -0500

    c++: fix ICE with -Wduplicated-cond [PR107593]

    Here we crash because a CAST_EXPR, representing T(), doesn't have
    its operand, and operand_equal_p's STRIP_ANY_LOCATION_WRAPPER doesn't
    expect that.  (o_e_p is called from warn_duplicated_cond_add_or_warn.)

    In the past we've adjusted o_e_p to better cope with template codes,
    but in this case I think we just want to avoid attempting to warn
    about inst-dependent expressions; I don't think I've ever envisioned
    -Wduplicated-cond to warn about them.  Also destroy the chain when
    an inst-dependent expression is encountered to not warn in
    Wduplicated-cond4.C.

    The ICE started with r12-6022, two-stage name lookup for overloaded
    operators, which gave dependent operators a TREE_TYPE (in particular,
    DEPENDENT_OPERATOR_TYPE), so we no longer bail out here in o_e_p:

      /* Similar, if either does not have a type (like a template id),
         they aren't equal.  */
      if (!TREE_TYPE (arg0) || !TREE_TYPE (arg1))
        return false;

            PR c++/107593
            PR c++/108597

    gcc/c-family/ChangeLog:

            * c-common.h (instantiation_dependent_expression_p): Declare.
            * c-warn.cc (warn_duplicated_cond_add_or_warn): If the condition
            is dependent, invalidate the chain.

    gcc/c/ChangeLog:

            * c-objc-common.cc (instantiation_dependent_expression_p): New.

    gcc/cp/ChangeLog:

            * cp-tree.h (instantiation_dependent_expression_p): Don't
            declare here.

    gcc/testsuite/ChangeLog:

            * g++.dg/warn/Wduplicated-cond3.C: New test.
            * g++.dg/warn/Wduplicated-cond4.C: New test.
            * g++.dg/warn/Wduplicated-cond5.C: New test.

Reply via email to