[clang] [clang-tools-extra] [Clang] Add support for the C `defer` TS (PR #162848)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 6 10:20:54 PST 2025


AaronBallman wrote:

> We talked about this PR a bit in my office hours yesterday and one thing which came up for feedback to WG14 is that this should be spelled `_Defer` and not `defer` if the committee is serious about the feature (which I believe they are). It's going into a TS, and so users have to opt-in for `defer` to become a keyword which may break their code. That's fine and we can live with it. But when `defer` is rolled into the IS, that makes for a harder migration path. But more importantly, we like this feature -- we want to expose it as a conforming extension in other language modes; that's not possible with the keyword spelled `defer` because that'd be a non-conforming extension. And from looking at available open source code, the identifier `defer` is used quite frequently.

Following up on this, the author of the TS has modified their draft to require `_Defer` as the keyword, provide an option for an implementation to additionally support `defer` as the keyword (the feature test macro now resolves to a value which tells you whether `defer` is supported or only `_Defer`), adds a `<stddefer.h>` header with the expected macros, and allows attributes on the defer statement.

I recommend we only support `_Defer` as a keyword and let users include `<stddefer.h>` to get the prettier spelling. I think we should vend that header file ourselves instead of leaving it to a C library (that makes deployment of the feature easier; we're not having to wait for standard libraries to also choose to support the TS).

https://github.com/llvm/llvm-project/pull/162848


More information about the cfe-commits mailing list