[Bug c++/126324] [13/14/15/16/17 Regression] Virtual function call with covariant return in constant evaluation causes ICE

"cvs-commit at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126324

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

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

commit r17-3321-geb54aa2d961ec016d15bd39ea62579af4ad25710
Author: Odysseas Georgoudis <[email protected]>
Date:   Fri Jul 24 23:18:32 2026 +0100

    c++: Adjust constexpr covariant call results [PR126324]

    Constant evaluation of a virtual call can evaluate the final overrider
    directly.  For a zero-offset covariant override, the result then has the
    overrider's declared type rather than the static type of the call.  Storing
    that result can make cxx_eval_store_expression mistake the scalar type
    mismatch for an empty-base initialization and ICE.

    For a nonzero covariant adjustment, virtual lookup uses a result thunk.
    cxx_eval_thunk_call applied the fixed offset even to a null result and left
    the adjusted result with the overrider's return type, causing the same type
    mismatch.

    Adjust successful virtual-call results to the static call type after
    caching the underlying function result.  Make result-thunk evaluation
    preserve null pointers, evaluate the call only once, and give the result
    the thunk's static return type.

    gcc/cp/ChangeLog:

            PR c++/126324
            * constexpr.cc (cxx_eval_thunk_call): Preserve null pointer
            results and adjust the result to the thunk's return type.
            (cxx_eval_call_expression): Adjust covariant virtual-call results
            to the static call type.

    gcc/testsuite/ChangeLog:

            PR c++/126324
            * g++.dg/cpp2a/constexpr-virtual-pr126324.C: New test.

    Signed-off-by: Odysseas Georgoudis <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.