Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: MicrosoftDocs/cpp-docs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: ceztko/cpp-docs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Sep 12, 2026

  1. State that [[msvc::forceinline]] behaves similarly to __forceinline b…

    …ut preserves the symbol in the TU
    
    The documentation treated [[msvc::forceinline]] as a synonym of __forceinline, but
    they don't have the same exact behavior. In a empirical test, a Link Time Optimization
    enabled build of a static library had a method marked as __forceinline elided
    from the final objects, causing a linking error when trying to consume the
    static library from a non-LTO enabled exe or shared library. The method definition
    is *not* present/visible in the header. Instead, [[msvc::forceinline]] was able to
    both intra-optimize the static library and create a symbol for the annotated function,
    allowing link from a consumer which has not visibility of the definition.
    
    For more context, the behavior of [[msvc::forceinline]] aligns with the behavior
    of the gcc specific always_inline[1] attribute, and clang also observes
    the same behavior.
    
    Below the results of a probe using VS 2026 and VS 2022.
    -----------------------------------------------
    == toolchains ==
    -- 18 (18.10.12201.205): Visual Studio 18 2026
       C:\Program Files\Microsoft Visual Studio\18\Community
    -- 2022 (17.14.37531.7): Visual Studio 17 2022
       C:\Program Files\Microsoft Visual Studio\2022\Community
    -- cmake: cmake version 4.3.2
    
    == results ==
    
    VS      Annotation               LTO    Library    Exe               Shlib             Symbols     Note
    ----    ---------------------    ---    -------    --------------    --------------    --------    ----
    18      none                     OFF    OK         LINK-OK RUN-OK    LINK-OK RUN-OK    present
    18      none                     ON     OK         LINK-OK RUN-OK    LINK-OK RUN-OK    n/a (IL)
    18      __forceinline            OFF    OK         LINK-FAIL         LINK-FAIL         absent
    18      __forceinline            ON     OK         LINK-FAIL         LINK-FAIL         n/a (IL)
    18      [[msvc::forceinline]]    OFF    OK         LINK-OK RUN-OK    LINK-OK RUN-OK    present
    18      [[msvc::forceinline]]    ON     OK         LINK-OK RUN-OK    LINK-OK RUN-OK    n/a (IL)
    2022    none                     OFF    OK         LINK-OK RUN-OK    LINK-OK RUN-OK    present
    2022    none                     ON     OK         LINK-OK RUN-OK    LINK-OK RUN-OK    n/a (IL)
    2022    __forceinline            OFF    OK         LINK-FAIL         LINK-FAIL         absent
    2022    __forceinline            ON     OK         LINK-FAIL         LINK-FAIL         n/a (IL)
    2022    [[msvc::forceinline]]    OFF    OK         LINK-OK RUN-OK    LINK-OK RUN-OK    present
    2022    [[msvc::forceinline]]    ON     OK         LINK-OK RUN-OK    LINK-OK RUN-OK    n/a (IL)
    
    == verdict ==
    18 lto=OFF: PARITY, [[msvc::forceinline]] keeps the symbol where __forceinline drops it
    18 lto=ON: PARITY, [[msvc::forceinline]] keeps the symbol where __forceinline drops it
    2022 lto=OFF: PARITY, [[msvc::forceinline]] keeps the symbol where __forceinline drops it
    2022 lto=ON: PARITY, [[msvc::forceinline]] keeps the symbol where __forceinline drops it
    -----------------------------------------------
    
    [1] https://gcc.gnu.org/onlinedocs/gcc/Common-Attributes.html#index-always_005finline
    ceztko committed Sep 12, 2026
    Configuration menu
    Copy the full SHA
    3d44d59 View commit details
    Browse the repository at this point in the history
Loading