GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
c++

C++ constexpr virtual call results adjusted for covariant overrides

Fixes ICE in constexpr evaluation of covariant virtual calls by correctly handling return types.

Constant evaluation of C++ virtual calls, especially with covariant return types, could lead to internal compiler errors (ICEs) due to type mismatches. This fix ensures that the result of a constexpr virtual call, including those involving result thunks for covariant overrides, is correctly adjusted to the static type of the call before being used in subsequent expressions, preventing the ICE.

In Details

In constexpr evaluation, virtual calls that resolve to their final overrider directly, especially covariant overrides with a zero offset, could lead to the overrider's return type being used instead of the static call type. This mismatch caused cxx_eval_store_expression to ICE. The fix in cxx_eval_call_expression and cxx_eval_thunk_call now correctly adjusts the result type to match the static call type, and preserves null pointers in thunk calls.

For Context
constexpr
A C++ keyword that allows certain expressions and function calls to be evaluated at compile time, improving performance by pre-calculating values.
virtual call
A function call where the specific function to be executed is determined at runtime based on the actual type of the object, used for polymorphism.
covariant override
In C++, a derived class's overriding virtual function can have a return type that is a derived type of the base class's virtual function return type.
ICE
Internal Compiler Error. A fatal error condition within the compiler itself, indicating a bug that prevents compilation.
Filed Under: c++constexproptimizationcompiler bug