Skip to content

Missing identifier 'ctz'/'ctzll' when compiling with MSVC and /clr #2176

Description

@Brainy0207

If I try to use fmt in a MSVC project with /clr enabled, I get the following errors:

1>D:\Temp\ConsoleApplication1\fmt-7.1.3\include\fmt\format-inl.h(2017,11): error C3861: 'ctz': identifier not found
1>D:\Temp\ConsoleApplication1\fmt-7.1.3\include\fmt\format-inl.h(2045,11): error C3861: 'ctzll': identifier not found

Here is a simple example to reproduce these errors:

#define FMT_HEADER_ONLY
#include <fmt/format.h>

int main()
{
}

It seems due to _MANAGED beeing defined in /clr builds, the replacement funtions for 'clz', 'clzll', 'ctz' and 'ctzll' are never defined and missing.

fmt/include/fmt/format.h

Lines 206 to 207 in af56753

#if FMT_MSC_VER && !defined(FMT_BUILTIN_CLZLL) && \
!defined(FMT_BUILTIN_CTZLL) && !defined(_MANAGED)

I think the better approach here would be to remove the _MANAGED check and instead force this section to native mode, to be able to use intrinsics without warnings:

// Switch to native
#pragma managed(push,off)
// Do native stuff here
#pragma managed(pop)
// Switch back to previous mode

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions