Can use C++ Modules due to /Zc:twoPhase- even though I didn't specify it.

周 瑶 41 Reputation points
2021-11-06T08:57:27.277+00:00

When I use VS2019 to compile following code in Debug-X86:

import std.core;
using namespace std;
int main()
{
 cout << "AMD yes." << endl;
}

It says:
fatal error C1214: Modules conflict with non-standard behavior requested via '/Zc:twoPhase-'
But I never specify that option. And my Command Line in Properties is:

/JMC /experimental:module /permissive- /MP /ifcOutput "Debug\" /GS /analyze- /W3 /Zc:wchar_t /ZI /Gm- /O2 /sdl /Fd"Debug\vc142.pdb" /Zc:inline /fp:precise /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_CRT_SECURE_NO_WARNINGS" /D "WXUSINGDLL" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /Oy- /Oi /MDd /openmp- /std:c++latest /FC /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\boostjson.pch" /diagnostics:column 

You can see there is no /Zc:twoPhase-.

Strangely if I compile in Release-X64, there is no problem. The Command Line is:

/experimental:module /permissive- /ifcOutput "x64\Release\" /GS /GL /W3 /Gy /Zc:wchar_t /Zi /Gm- /O2 /sdl /Fd"x64\Release\vc142.pdb" /Zc:inline /fp:precise /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /Oi /MD /openmp- /std:c++latest /FC /Fa"x64\Release\" /EHsc /nologo /Fo"x64\Release\" /Fp"x64\Release\boostjson.pch" /diagnostics:column 

Also there is the same problem in Release-X86:

   /experimental:module /permissive- /ifcOutput "Release\" /GS /GL /analyze- /W3 /Gy /Zc:wchar_t /Zi /Gm- /O2 /sdl /Fd"Release\vc142.pdb" /Zc:inline /fp:precise /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_CRT_SECURE_NO_WARNINGS" /D "WXUSINGDLL" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /Oy- /Oi /MD /openmp- /std:c++latest /FC /Fa"Release\" /EHsc /nologo /Fo"Release\" /Fp"Release\boostjson.pch" /diagnostics:column 
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,544 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. RLWA32 40,771 Reputation points
    2021-11-06T11:08:44.173+00:00

    I could not reproduce the issue with VS2019 16.11.5 in debug and release builds for both x86 and x64. I started with an Empty project and added a source file into which I pasted the posted code. The only changes that I made to project options across all configurations/platforms were to set /std:c++latest and /experimental:module.

    Each build completed successfully although warning messages were issued by the compiler.

    x86 - Debug build output -

    Build started...
    1>------ Build started: Project: ModuleTest, Configuration: Debug Win32 ------
    1>Source.cpp
    1>C:\Users\RLWA32\source\repos\ModuleTest\ModuleTest\Source.cpp(1,16): warning C5050: Possible incompatible environment while importing module 'std.core': _GUARDOVERFLOW_CRT_ALLOCATORS=1 is defined in current command line and not in module command line
    1>C:\Users\RLWA32\source\repos\ModuleTest\ModuleTest\Source.cpp(1,16): warning C5050: Possible incompatible environment while importing module 'std.core': _DEBUG is defined in current command line and not in module command line
    1>C:\Users\RLWA32\source\repos\ModuleTest\ModuleTest\Source.cpp(1,16): warning C5050: Possible incompatible environment while importing module 'std.core': _M_FP_PRECISE is defined in current command line and not in module command line
    1>   Creating library C:\Users\RLWA32\source\repos\ModuleTest\Debug\ModuleTest.lib and object C:\Users\RLWA32\source\repos\ModuleTest\Debug\ModuleTest.exp
    1>ModuleTest.vcxproj -> C:\Users\RLWA32\source\repos\ModuleTest\Debug\ModuleTest.exe
    1>Done building project "ModuleTest.vcxproj".
    ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
    

    x86 Debug Command line -

    /JMC /experimental:module /permissive- /ifcOutput "Debug\" /GS /analyze- /W3 /Zc:wchar_t /ZI /Gm- /Od /sdl /Fd"Debug\vc142.pdb" /Zc:inline /fp:precise /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /std:c++latest /FC /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\ModuleTest.pch" /diagnostics:column 
    

    x86 Release Build Output

    Build started...
    1>------ Build started: Project: ModuleTest, Configuration: Release Win32 ------
    1>Source.cpp
    1>C:\Users\RLWA32\source\repos\ModuleTest\ModuleTest\Source.cpp(1,16): warning C5050: Possible incompatible environment while importing module 'std.core': _GUARDOVERFLOW_CRT_ALLOCATORS=1 is defined in current command line and not in module command line
    1>C:\Users\RLWA32\source\repos\ModuleTest\ModuleTest\Source.cpp(1,16): warning C5050: Possible incompatible environment while importing module 'std.core': _M_FP_PRECISE is defined in current command line and not in module command line
    1>   Creating library C:\Users\RLWA32\source\repos\ModuleTest\Release\ModuleTest.lib and object C:\Users\RLWA32\source\repos\ModuleTest\Release\ModuleTest.exp
    1>Generating code
    1>Previous IPDB not found, fall back to full compilation.
    1>All 6 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
    1>Finished generating code
    1>ModuleTest.vcxproj -> C:\Users\RLWA32\source\repos\ModuleTest\Release\ModuleTest.exe
    1>Done building project "ModuleTest.vcxproj".
    ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
    

    x86 Release Command line -

    /experimental:module /permissive- /ifcOutput "Release\" /GS /GL /analyze- /W3 /Gy /Zc:wchar_t /Zi /Gm- /O2 /sdl /Fd"Release\vc142.pdb" /Zc:inline /fp:precise /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /Oy- /Oi /MD /std:c++latest /FC /Fa"Release\" /EHsc /nologo /Fo"Release\" /Fp"Release\ModuleTest.pch" /diagnostics:column 
    
    0 comments No comments

  2. Stein Somers 0 Reputation points
    2023-06-19T12:00:06.8466667+00:00

    I also got this error after upgrading Visual Studio. I also have /std:c++latest which in the UI is property C/C++ → Language → Preview - Features from the Latest C++ Working Draft. Fixed the issue by setting the last option on that page, "Build ISO C++23 Standard Library Modules", to "No".

    0 comments No comments