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

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <[email protected]>:

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

commit r17-6695-ga95c1724b918b285ff1826fa6b94219c28dfd852
Author: Marek Polacek <[email protected]>
Date:   Tue Nov 24 14:56:08 2026 -0500

    c++/reflection: ICE with consteval-only var [PR128941]

    mark_needed asserts that it doesn't get a consteval_only_p decl.
    In this test it does get it, though, so we crash.  So guard the
    mark_needed call in cp_finish_decl with !consteval_only_p.

    Further testing revealed that we also call mark_needed in
    setup_explicit_instantiation_definition_linkage and that needs
    a similar guard.

    The DECL_INLINE_VAR_P check in cp_finish_decl is interesting.
    Per CWG2531 it should be false for I::value in

      struct I {
        static consteval info foo() { return ^^int; }
        static const info value;
      };
      constexpr info I::value = I::foo();

    but it's true so we reach the mark_needed block.  But this fix is
    correct anyway, we would reach this block with I2 which has the
    constexpr in-class.

            PR c++/128941

    gcc/cp/ChangeLog:

            * decl2.cc (maybe_make_one_only): Turn the consteval_only_p
            assert into a condition and return early if it's true.
            (mark_needed): Likewise.

    gcc/testsuite/ChangeLog:

            * g++.dg/reflect/value17.C: New test.
            * g++.dg/reflect/value18.C: New test.

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

Reply via email to