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

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

https://gcc.gnu.org/g:f7990da34872cfb448d4d1341714508904cb666c

commit r17-1276-gf7990da34872cfb448d4d1341714508904cb666c
Author: Patrick Palka <[email protected]>
Date:   Wed Jun 3 18:03:14 2026 -0400

    c++: unchecked 'A op B' constraint-expression [PR125490]

    Here the nonsensical constraint-expression f() == 42 isn't getting rejected
    ahead of time because when parsing we pass no_toplevel_fold_p=true to
    cp_parser_binary_expression, which makes it use build_min instead of
    build_x_binary_op, effectively bypassing the actual processing of the
    operator expression until satisfaction time.  This flag was introduced
    by r145014 to avoid undesirable folding / canonicalization of OpenMP for
    loop conditions, and that's still the only other user of the flag today.

    But I think cp_parser_constraint_expression doesn't need to use this
    flag at all because constraint-expression parsing is always templated
    and we (generally) don't fold templated trees.  I think the flag is
    intended to be used only by OpenMP parsing routines.

    Note that without this patch we'd go on to reject the constraint-expression
    at satisfaction time, so this first testcase is effectively IFNDR / QoI.
    But this change isn't limited to IFNDR cases, we need to process the
    operator expression at parse time for sake of correct unqualified lookup
    as in the second testcase.

            PR c++/125490

    gcc/cp/ChangeLog:

            * parser.cc (cp_parser_constraint_expression): Pass
            no_toplevel_fold_p=false instead of =true to
            cp_parser_binary_expression.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/concepts-pr125490.C: New test.
            * g++.dg/cpp2a/concepts-pr125490a.C: New test.

    Reviewed-by: Jason Merrill <[email protected]>

Reply via email to