microsoft / STL

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

<yvals.h> : Can't be used alongside the std module #4670

Closed Cazayus closed 1 month ago

Cazayus commented 1 month ago

Describe the bug

It is currently impossible to use the yvals header with the std module yvals.h is not a STL header, so it should not be affected by the current limitation of mixing import std and includes.

Command-line test case

C:\Temp>type repro.cpp
import std;
#define align_val_t ignore_align_val_t // only here to silence the error of issue #4666

#include <yvals.h>

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

C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.40.33807\include\yvals.h(333): error C2011: 'std::_Uninitialized': 'enum' type redefinition
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.40.33807\include\yvals.h(333): note: see declaration of 'std::_Uninitialized'

Expected behavior

It should compile but does not

STL version

    Microsoft Visual Studio Community 2022
    Version 17.10.0 Preview 7.0
StephanTLavavej commented 1 month ago

yvals.h is not a STL header

Actually, it is - <yvals.h> is one of the STL's central internal headers: (<yvals_core.h> is the "most central", but <yvals.h> is a runner-up.)

https://github.com/microsoft/STL/blob/8dc4faadafb52e3e0a627e046b41258032d9bc6a/stl/inc/yvals.h#L1

Being part of the STL, <yvals.h> is definitely affected by our current implementation bug/limitation of import-before-include resulting in duplicated machinery (like the internal std::_Uninitialized type).

Also, because it's an internal header, user code shouldn't directly include <yvals.h>. (This is unlike <crtdbg.h>, which is a documented Microsoft-specific header.)

I'm going to resolve this as a duplicate of #4666, even though it's a bit different, because it's the same root cause which will need the same coordinated fix between the compiler and Standard Library to make arbitrary mixing of imports and includes work.

Thanks yet again for the thorough reports! :smile_cat: