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

--- Comment #6 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:801c6fbeec194f48a49198727ce9bc54cd209713

commit r16-8146-g801c6fbeec194f48a49198727ce9bc54cd209713
Author: Jakub Jelinek <[email protected]>
Date:   Wed Mar 18 06:36:15 2026 +0100

    c++: Fix up reflect/init11.C on cdtor_returns_this targets [PR124474]

    On arm*-linux-gnueabi init11.C emits extra diagnostics which the testcase
    doesn't expect.
    E.g. it emits
    init11.C: At global scope:
    init11.C:19:13: error: function of consteval-only type must be declared
âconstevalâ
       19 |   constexpr C() : i{} {}  // { dg-error "function of consteval-only
type must be declared .consteval." }
          |             ^
    init11.C: In constructor âconstexpr C::C()â:
    init11.C:19:24: error: consteval-only expressions are only allowed in a
constant-evaluated context
       19 |   constexpr C() : i{} {}  // { dg-error "function of consteval-only
type must be declared .consteval." }
          |                        ^
    while on most other targets only the first error from these and not
    the second is emitted.
    This is because of targetm.cxx.cdtor_returns_this (), the error is emitted
    on the constructor declaration and then again during
    check_out_of_consteval_use on its body, when walking RETURN_EXPR (which
    normally isn't there).

    The following patch arranges diagnostics parity.

    Though, as I wrote in the PR, I wonder if it makes sense to report
    any errors on bodies of functions for which we've already diagnosed
    function of consteval-only type must be declared âconstevalâ.
    Especially for methods of consteval-only types, any use of this keyword
    will result in an extra error (sure, only the first occurrence in a
    function).  But even if a function has only some other consteval-only
    argument and that argument is used somewhere in the body.  Though, wonder
    if it is worth trying to improve that now when we don't know if
    consteval-only will not be removed completely or changed significantly.

    2026-03-18  Jakub Jelinek  <[email protected]>

            PR c++/124474
            * reflect.cc (check_out_of_consteval_use_r): Don't walk subtrees
            of RETURN_EXPR on cdtor_returns_this targets in cdtors.

Reply via email to