microsoft / STL

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

Module STD : Another error with crtdbg header #4667

Closed Cazayus closed 1 month ago

Cazayus commented 1 month ago

Describe the bug

It is possible to work around the issue #4666 with a #define, but the following code still fails to compile with another error. Seemed worth reporting separately just in case.

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

void mainNew()
{
    std::pmr::memory_resource* m_upstream;
    m_upstream->allocate(0);
}

#include <crtdbg.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\vcruntime_new.h(162): error C2084: function 'void *operator new(size_t,void *) noexcept' already has a body
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.40.33807\include\vcruntime_new.h(162): note: see previous definition of 'operator new'
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.40.33807\include\vcruntime_new.h(162): error C3615: constexpr function 'operator new' cannot result in a constant expression
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.40.33807\include\vcruntime_new.h(162): note: failure was caused by control reaching the end of a constexpr function

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

Thanks for the report - this is a duplicate of #4666. While the error is different (::operator new instead of std::align_val_t), the root cause is the same - <crtdbg.h> drags in VCRuntime, and VCRuntime has to export a bit of Standard Library machinery, so this is the import-before-include scenario that's blocked by our implementation bug/limitation.

I appreciate the report even though it turned out to be a duplicate (sometimes similar-looking bugs are actually distinct).