microsoft / STL

MSVC's implementation of the C++ Standard Library.
Other
9.89k stars 1.45k forks source link

<atomic> : A standard macro is not exported when using the std module #4669

Closed Cazayus closed 1 month ago

Cazayus commented 1 month ago

Describe the bug

A simple case copy pasted from cppreference.com does not work when replacing the atomic include by the std module https://en.cppreference.com/w/cpp/atomic/ATOMIC_FLAG_INIT

Command-line test case

C:\Temp>type repro.cpp
import std;
//#include <atomic>

std::atomic_flag static_flag = ATOMIC_FLAG_INIT; // static initialization,
// guaranteed to be available during dynamic initialization of static objects.

void mainAtomic()
{
    std::atomic_flag automatic_flag = ATOMIC_FLAG_INIT; // guaranteed to work
//    std::atomic_flag another_flag(ATOMIC_FLAG_INIT); // unspecified
}

C:\Temp>cl.exe /std:c++latest /EHsc /nologo /c .\repro.cpp

error C2065: 'ATOMIC_FLAG_INIT': undeclared identifier

Expected behavior

It should compile but does not

STL version

    Microsoft Visual Studio Community 2022
    Version 17.10.0 Preview 7.0

Additional context

Seen when using the Boost library

frederick-vs-ja commented 1 month ago

Not a bug IIUC. The std module can't provide any macro.

Cazayus commented 1 month ago

You're probably right, the cppref page mentions : "Since c++20 : This macro is no longer needed since default constructor of std::atomic_flag initializes it to clear state. It is kept for the compatibility with C." I guess most code that uses this should be updated accordingly post-cpp20

StephanTLavavej commented 1 month ago

Correct - all named modules, including the Standard Library Modules std and std.compat, are by-Core-Language-design unable to emit macros, so alternative mechanisms must be found.

Thanks for being an early adopter of modules! :heart_eyes_cat: