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

std::filesystem::directory_iterator code compiles OK with <filesytem> fails with std module, 17.5 Preview 2 #3330

Closed
davidhunter22 opened this issue Jan 8, 2023 · 4 comments · Fixed by #3331
Labels
bug Something isn't working fixed Something works now, yay! modules C++23 modules, C++20 header units

Comments

@davidhunter22
Copy link

The following code compiles OK when using the <filesystem> header but fails when using import std;. This is with 17.5 Preview 2. The only changes to a default C++ project in VS was /std:c++latest and adding the std.ixx file

import std;

// #include <filesystem>

int main( )
{
    for (auto a : std::filesystem::directory_iterator( "C:\\" )) { }

    return 0;
}

The error message when using the std module is

1>C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.35.32124\include\type_traits(2102,13): error C2678: binary '&': no operator found which takes a left-hand operand of type '_Bitmask' (or there is no acceptable conversion)
1>        with
1>        [
1>            _Bitmask=__std_fs_file_attr
1>        ]
1>C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.35.32124\include\cstddef(49,39): message : could be 'std::byte std::operator &(const std::byte,const std::byte) noexcept'
1>C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.35.32124\include\type_traits(2102,13): message : while trying to match the argument list '(_Bitmask, _Bitmask)'
1>        with
1>        [
1>            _Bitmask=__std_fs_file_attr
1>        ]
1>C:\Users\david\devel\bugs\mudule_filesystem\Project1\Test.cpp(10,1): message : see reference to function template instantiation 'bool std::_Bitmask_includes_any<__std_fs_file_attr>(_Bitmask,_Bitmask) noexcept' being compiled
1>        with
1>        [
1>            _Bitmask=__std_fs_file_attr
1>        ]
1>Done building project "Project1.vcxproj" -- FAILED.

Which seemed really odd to me.

@fsb4000
Copy link
Contributor

fsb4000 commented Jan 8, 2023

If I change the code

_BITMASK_OPS(_EMPTY_ARGUMENT, __std_fs_file_attr)

to

_BITMASK_OPS(_EXPORT_STD, __std_fs_file_attr)

then your example works for me.

But I am unsure should we add _EXPORT_STD or is this a compiler bug?

@davidhunter22
Copy link
Author

Beyond my pay grade! What got me was why it is "operator &" in what I assume is an assignment of the dereferenced directory iterator. operator & to me would normally be a boolean and of the bits in the attribute flags.

Anyway I'll leave it to the experts. My only other comment is that it's a bit annoying that the error message doesn't tell me what line in my code is causing the issue. The line number in my code in the the error is simply the last one in the main function not the one causing the error.

@StephanTLavavej
Copy link
Member

@fsb4000's library workaround, and @cdacamar's compiler fix for the root cause, will both ship in VS 2022 17.6 Preview 2. Thanks again for the report.

@matbech
Copy link

matbech commented Jan 18, 2023

In 17.5 Preview 3, I do have the same issue with __std_fs_stats_flags

1>C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.35.32213\include\type_traits(2102,13): error C2678: binary '&': no operator found which takes a left-hand operand of type '_Bitmask' (or there is no acceptable conversion)
1>        with
1>        [
1>            _Bitmask=__std_fs_stats_flags
1>        ]

With the same library workaround as with __std_fs_file_attr it compiles:

#if 1 // TRANSITION, DevCom-10247495
_BITMASK_OPS(_EXPORT_STD, __std_fs_stats_flags)
#else // ^^^ workaround / no workaround vvv
_BITMASK_OPS(_EMPTY_ARGUMENT, __std_fs_stats_flags)
#endif // ^^^ no workaround ^^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Something works now, yay! modules C++23 modules, C++20 header units
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants