You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
164
+
The `[[msvc::musttail]]` attribute, introduced in [MSVC Build Tools version 14.50](../overview/what-s-new-for-msvc.md#whats-new-for-msvc-build-tools-version-1450), is an experimental x64 only Microsoft-specific attribute that enforces tail-call optimization. When applied to a qualifying return statement, it instructs the compiler to emit the call as a tail call. If the compiler can't emit the tail call, it produces a compilation error. The `[[msvc::musttail]]` attribute enforces tail calling over function inlining.
164
165
165
-
The `[[msvc::musttail]]`attribute has constraints:
166
+
`[[msvc::musttail]]`requirements:
166
167
- The caller and callee must have matching return types.
167
168
- The calling conventions must be compatible.
168
169
- The tail call must be the final action in the calling function.
169
-
- The callee must not use more stack space than the calling function.
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
170
+
- The callee can't use more stack space than the calling function.
171
+
- If more than four integer parameters are passed, the calling function must allocate enough stack space for those additional arguments.
172
+
-Compile with `/O2` or `/O2 /GL` optimization level.
172
173
173
174
#### Example
174
175
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`.
176
+
In the following code, the `[[msvc::musttail]]` attribute applied to `return increment(x)`causes execution to jump from `increment` to `incrementIfPositive` before returning to `main`, rather than inlining `increment` into `incrementIfPositive` or calling `increment` from `incrementIfPositive` and returning to `incrementIfPositive` before returning to `main`.
0 commit comments