Skip to content

Commit 158d9cb

Browse files
authored
Update documentation for [[msvc::musttail]] attribute
Clarified the description of the [[msvc::musttail]] attribute and fixed typos.
1 parent 66ed08c commit 158d9cb

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

docs/cpp/attributes.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,19 @@ void f() {
160160
```
161161
### `[[msvc::musttail]]`
162162

163-
The `[[msvc::musttail]]` attribute is an experimental x64 only Microsoft-specific attribute that enforces tail-call optimization for a given function call. When applied on a qualifying return statement, it instructs the compiler to emit the call as a tail call. If the compiler cannot do so, it will produce a compilation error. The `[[msvc::musttail]]` attribute will enforce tail calling over inlining of a function.
163+
The `[[msvc::musttail]]` attribute is an experimental x64 only Microsoft-specific attribute introduced in [MSVC Build Tools version 14.50](https://learn.microsoft.com/en-us/cpp/overview/what-s-new-for-msvc?view=msvc-170) that enforces tail-call optimization for a given function call. When applied on a qualifying return statement, it instructs the compiler to emit the call as a tail call. If the compiler cannot do so, it will produce a compilation error. The `[[msvc::musttail]]` attribute will enforce tail calling over inlining of a function.
164164

165165
The `[[msvc::musttail]]` attribute has constraints:
166166
- The caller and callee must have matching return types.
167167
- The calling conventions must be compatible.
168-
- The tail call must be in the return position (i.e., the final action in the calling function).
168+
- The tail call must be the final action in the calling function.
169169
- The callee must not use more stack space than the calling function.
170-
- If more than 4 integer parameters are passed, the calling function must allocate enough stack space for those additional arguments. Please see __preserve_none calling convention for tail calling without additional stack overhead.
171-
- Other compiler optimizations must be enabled.
170+
- If more than four integer parameters are passed, the calling function must allocate enough stack space for those additional arguments. Please see `__preserve_none` calling convention for tail calling without additional stack overhead.
171+
- Must compile with `/O2` or `/O2 /GL` optimization level
172172

173173
#### Example
174174

175-
In this sample code, the `[[msvc::musttail]]` attribute applied to the return bar function call forces execution to jump from foo to bar before returning to main, rather than inlining bar into foo or calling bar from foo and returning to foo before returning to main.
175+
In the follwoing code, the `[[msvc::musttail]]` attribute applied to the `return bar(x)` call forces execution to jump from `foo` to `bar` before returning to `main`, rather than inlining `bar` into `foo` or calling `bar` from `foo` and returning to `foo` before returning to `main`.
176176

177177
```cpp
178178
int bar(int x) {
@@ -182,9 +182,9 @@ int bar(int x) {
182182
int foo(int x) {
183183
if(x > 0){
184184
[[msvc::musttail]]
185-
return bar(x);
185+
return bar(x);
186186
}
187-
return -1;
187+
return -1;
188188
}
189189

190190
int main() {

0 commit comments

Comments
 (0)