GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
c++

C++: co_await and ->* operator: Fix TARGET_EXPR handling.

GCC's coroutine support now correctly handles `TARGET_EXPR` when used with member function pointers and `co_await`.

This commit improves GCC’s handling of co_await when used with C++ member function pointers. A change in GCC version r13-9563 caused TARGET_EXPR to be used in get_member_function_from_ptrfunc, which conflicted with how flatten_await_stmt processes such expressions. This fix accommodates the reuse of TARGET_EXPR by flatten_await_stmt, resolving issues for coroutines involving member function pointers and co_await, as reported in PR121094 and PR117259.

In Details

The replace_proxy function in coroutines.cc now correctly handles TARGET_EXPR originating from get_member_function_from_ptrfunc. Previously, it did not properly support the reuse of TARGET_EXPR within flatten_await_stmt, leading to breakage when co_await was applied to member function pointers. This patch ensures that flatten_await_stmt can pass TARGET_EXPRs correctly, resolving PR121094 and PR117259.

For Context
`co_await`
A C++20 coroutine keyword that suspends the execution of a coroutine until an asynchronous operation completes. It interacts with the coroutine's state machine and frame.
Member function pointer
A type that points to a member function of a class. In C++, calling a member function typically requires an object instance; a member function pointer stores the function's address and needs an object to be invoked upon.
`TARGET_EXPR`
An internal GCC representation for a temporary object created within a full-expression that has a lifetime tied to that expression. It's often used for intermediate results.
Coroutines
Functions that can suspend their execution and resume later, allowing for more flexible asynchronous programming patterns. C++20 introduced coroutine support.
`flatten_await_stmt`
An internal GCC compiler function responsible for processing and simplifying co_await expressions within coroutines.
Filed Under: c++coroutinesmember function pointer