IT lexicon › Programming › musttail

musttail

Programming På svenska → Updated: 2026-11-05

An attribute that turns tail-call optimization from a suggestion into a demand: the compiler jumps to the callee, and if it can't, compilation fails.

C and C++ promise nothing about tail calls. The optimizer does them when it feels like it, which means code that runs fine at -O2 blows the stack in a debug build. LLVM IR has long had a musttail marker, and Clang 13 exposed it in 2021 as [[clang::musttail]]. The push came from Josh Haberman, who built a protobuf parser in which every field type is its own function that tail-calls the next — a style that only works if every jump is guaranteed.

The catch is that caller and callee need compatible signatures, so the arguments can stay where the calling convention put them. GCC 15 gained an equivalent attribute, and Rust has an experimental keyword, become, for the same job.

← Back to the lexicon