Skip to content

Fix MSVC C4864 warning and testlib message_impl link error#858

Merged
mjp41 merged 1 commit into
microsoft:mainfrom
matajoh:fix-template-windows
Jun 17, 2026
Merged

Fix MSVC C4864 warning and testlib message_impl link error#858
mjp41 merged 1 commit into
microsoft:mainfrom
matajoh:fix-template-windows

Conversation

@matajoh

@matajoh matajoh commented Jun 17, 2026

Copy link
Copy Markdown
Member

corealloc.h: small_refill and small_alloc are member templates invoked through an Allocator* of dependent type. MSVC's conformance mode requires the template disambiguator, otherwise it emits C4864 ("expected 'template' keyword before dependent template name"). Add the keyword to the three affected call sites.

snmalloc_testlib.cc: message_impl is declared non-inline in defines.h but defined inline in pal.h. On MSVC its COMDAT was never emitted into the test library (nothing referenced it), so testlib-only tests that see only the declaration (redblack, seqset) failed to link with LNK2019. Force-emit the COMDAT via a non-elidable odr-use, keeping the symbol inline everywhere so it stays ODR-safe with the copies other tests compile from snmalloc.h.

corealloc.h: `small_refill` and `small_alloc` are member templates invoked
through an `Allocator*` of dependent type. MSVC's conformance mode requires
the `template` disambiguator, otherwise it emits C4864 ("expected 'template'
keyword before dependent template name"). Add the keyword to the three
affected call sites.

snmalloc_testlib.cc: `message_impl` is declared non-inline in defines.h but
defined inline in pal.h. On MSVC its COMDAT was never emitted into the test
library (nothing referenced it), so testlib-only tests that see only the
declaration (redblack, seqset) failed to link with LNK2019. Force-emit the
COMDAT via a non-elidable odr-use, keeping the symbol inline everywhere so it
stays ODR-safe with the copies other tests compile from snmalloc.h.

Signed-off-by: Matthew Johnson <matjoh@microsoft.com>

@mjp41 mjp41 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@mjp41 mjp41 merged commit 526c55b into microsoft:main Jun 17, 2026
198 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants