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

--- Comment #11 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <[email protected]>:

https://gcc.gnu.org/g:71c2e6c2bfcaf33227727181dffda8a3b05e4e9b

commit r16-7278-g71c2e6c2bfcaf33227727181dffda8a3b05e4e9b
Author: Jakub Jelinek <[email protected]>
Date:   Wed Feb 4 11:36:08 2026 +0100

    tree: Fix up wrong-code with certain C++ default arguments [PR123818]

    The following testcase is miscompiled since r0-69852-g4038c495f (at least
    if one can somehow arrange in C++98 to have AGGR_INIT_EXPR or any other
    FE specific trees nested in constructor elts for CONSTRUCTOR nested inside
    of default argument, if not, then since C++11 support that allows that has
    been implemented).
    The problem is that we unfortunately store default arguments in
TREE_PURPOSE
    of TYPE_ARG_TYPES nodes of the FUNCTION/METHOD_TYPE and those are shared,
    with type_hash_canon used to unify them.  The default arguments aren't
    considered in type_hash_canon_hash at all, but the equality hook considers
    them in type_list_equal by calling simple_cst_equal on those default
    arguments.  That function is a tri-state, returns 0 for surely unequal,
    1 for equal and -1 for "I don't know", usually because there are FE trees
    etc. (though, admittedly it is unclear why such distinction is done, as
    e.g. for VAR_DECLs etc. it sees in there it returns 0 rather than -1).
    Anyway, the r0-69852-g4038c495f change changed CONSTRUCTOR_ELTS from
    I think a tree list of elements to a vector and changed the
simple_cst_equal
    implementation of CONSTRUCTOR from just recursing on CONSTRUCTOR_ELTS
(which
    I think would just return -1 because I don't see simple_cst_equal having
    TREE_LIST nor TREE_VEC handling) to something that thinks simple_cst_equal
    returns a bool rather than tri-state, plus has a comment whether it should
    handle indexes too.
    So, in particular on the testcase which has in default arguments with
    CONSTRUCTOR inside it with AGGR_INIT_EXPR as the single element (but
    could be as well in multiple elements), the recursive call returns -1
    for "I don't know" on the element and the function considers it the same
    as if it returned 1, they are equal.

    The following patch fixes it by calling the recursive non tail-recursive
    simple_cst_equal calls like everywhere else in the function, by returning
    what it returned if it returned <= 0 and otherwise continuing.
    Plus given the comment I've also implemented checking the index.
    The special case for FIELD_DECL is so that if both indexes are FIELD_DECLs
    and they are different, we don't return -1 but 0.

    2026-02-04  Jakub Jelinek  <[email protected]>

            PR c++/123818
            * tree.cc (simple_cst_equal) <case CONSTRUCTOR>: Return -1 if some
            recursive call returns -1.  Also compare indexes.

            * g++.dg/cpp0x/pr123818.C: New test.

Reply via email to