Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation Error with MSVC (14.43.34808) with -std:c++latest #4391

Closed
wants to merge 1 commit into from

Conversation

ankurvdev
Copy link

Fixes the following error with MSVC

d:\vcpkg\installed\arm64-msvc-static-md\include\fmt\base.h(2302): error C2446: ':': no conversion from 'std::tuple<T1,T2>' to 'unsigned __int64'
        with
        [
            T1=fmt::v11::detail::<unnamed-enum-is_unpacked_bit>,
            T2=size_t
        ]
d:\vcpkg\installed\arm64-msvc-static-md\include\fmt\base.h(2302): note: the template instantiation context (the oldest one first) is
D:\optimlir\proto\CodeTemplates.h(103): note: see reference to function template instantiation 'std::string fmt::v11::format<fmt::v11::join_view<std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,char>>(fmt::v11::fstring<fmt::v11::join_view<std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,char>>,fmt::v11::join_view<std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,char> &&)' being compiled
        with
        [
            _Ty=std::string
        ]

Fixes the following error with MSVC
```
d:\vcpkg\installed\arm64-msvc-static-md\include\fmt\base.h(2302): error C2446: ':': no conversion from 'std::tuple<T1,T2>' to 'unsigned __int64'
        with
        [
            T1=fmt::v11::detail::<unnamed-enum-is_unpacked_bit>,
            T2=size_t
        ]
d:\vcpkg\installed\arm64-msvc-static-md\include\fmt\base.h(2302): note: the template instantiation context (the oldest one first) is
D:\optimlir\proto\CodeTemplates.h(103): note: see reference to function template instantiation 'std::string fmt::v11::format<fmt::v11::join_view<std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,char>>(fmt::v11::fstring<fmt::v11::join_view<std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,char>>,fmt::v11::join_view<std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,char> &&)' being compiled
        with
        [
            _Ty=std::string
        ]
```
@vitaut
Copy link
Contributor

vitaut commented Mar 17, 2025

This looks like a compiler bug since there is no std::tuple<T1,T2> there, please report to Microsoft. Also you were probably testing an old version since currently the underlying type is already unsigned long long and the cast has no effect.

@vitaut vitaut closed this Mar 17, 2025
@ankurvdev
Copy link
Author

ankurvdev commented Mar 17, 2025

@vitaut
Apologies if i'm misinterpreting but i dont think its a compiler bug. ( The message for tuple might be a compiler messaging bug )
I think enum implicit conversion to int was deprecated and now removed in the latest compiler which is causing this issue.

https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/c5054?view=msvc-170
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1120r0.html#dx-arithmetic-conversion-on-enumerations-deprarithconvenum

The cast is to make sure the enum is explicitly casted to underlying type so its not using the deprecated implicit casting

@dinomight
Copy link
Contributor

Likely need more information like what the code looks like that's instantiating the fmt templates. Just messing around with the enum idea on godbolt [0] suggests that it only applies when using an operator with two different enums, not between an enum and a size_t, as is the case here. That goes along with your paper link as that describes enum/enum or enum/float operations as being deprecated, but not enum/int. clang 20 appears to agree with the latest version of MSVC on godbolt with how these enums are interacting with operators.

[0] https://godbolt.org/z/jGv1q8dzj

@ankurvdev
Copy link
Author

ankurvdev commented Mar 17, 2025

@dinomight you compiled with c++20. This is only deprecated in c++20

You code fails to compile with c++26

<source>:8:22: error: invalid bitwise operation between different enumeration types ('Foo' and 'Bar')
    8 |     return Foo::FooA | Bar::BarA | value;
      |            ~~~~~~~~~ ^ ~~~~~~~~~
1 error generated.
ASM generation compiler returned: 1
<source>:8:22: error: invalid bitwise operation between different enumeration types ('Foo' and 'Bar')
    8 |     return Foo::FooA | Bar::BarA | value;
      |            ~~~~~~~~~ ^ ~~~~~~~~~
1 error generated.
Execution build compiler returned: 1
example.cpp
<source>(8): warning C5054: operator '|': deprecated between enumerations of different types
ASM generation compiler returned: 0
example.cpp
<source>(8): warning C5054: operator '|': deprecated between enumerations of different types
Execution build compiler returned: 0
Program returned: 32

https://godbolt.org/z/5brhMaGWb

@dinomight
Copy link
Contributor

dinomight commented Mar 17, 2025

@dinomight you compiled with c++20. This is only deprecated in c++20

Correct, but the warnings were still generated under C++20 for both compilers (line 8). My point was that the enum/int combination (line 7) is not a warning and that's the one that mirrors the enum/size_t in this PR and has me wondering how you are instantiating the fmt templates.

And just to be clear, without a reproducible test case, it's unlikely this change will get merged as it doesn't look necessary at this time, as vitaut has already pointed out.

@ankurvdev
Copy link
Author

Thanks sorry I missed that earlier (line 7 is being successfully compiled)
I'll report this to the MSVC compiler folks and see if i can get a concise godbolt repro for the issue

@vitaut
Copy link
Contributor

vitaut commented Mar 22, 2025

The message for tuple might be a compiler messaging bug

Yes and that's what I was suggesting to report.

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.

3 participants