I'm trying to change the compiler collection of a project which uses a lot of exceptions (try/catch blocks) from Microsoft Visual C++ to LLVM, but ran into compilation issues.
Used tool chain:
- Visual Studio 2015 Enterprise (MSVC 14)
- LLVM 3.7 Windows/x64
Here is some test source code:
#include <iostream>
int main()
{
try
{
throw 20;
}
catch (int e)
{
std::cout << "An exception occurred. Exception Nr. " << e << '\n';
}
return 0;
}
Compiling the code with the built-in Visual Studio compiler collection (v140), this are the command line results:
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe
/c /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D _MBCS /Gm /EHsc /RTC1 /MDd /GS /fp:precise
/Zc:wchar_t /Zc:forScope /Zc:inline /Fo "Debug\\" /Fd"Debug\vc140.pdb" /Gd /TP
/analyze- /errorReport:queue Main.cpp
Main.cpp
Link:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\link.exe
/ERRORREPORT:QUEUE /OUT:"C:\Users\jurocha\Desktop\ClangExcept\Debug\ClangExcept.exe"
/INCREMENTAL /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
/MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /Debug
/PDB:"C:\Users\jurocha\Desktop\ClangExcept\Debug\ClangExcept.pdb" /TLBID:1
/DYNAMICBASE /NXCOMPAT
/IMPLIB:"C:\Users\jurocha\Desktop\ClangExcept\Debug\ClangExcept.lib"
/MACHINE:X86 Debug\Main.obj
Compilation succeeds.
Now, changing the compilers to LLVM (LLVM-vs2014):
ClCompile:
C:\Program Files\LLVM\3.7\msbuild-bin\CL.exe
/c /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D _MBCS /Gm /EHsc /RTC1 /MDd /GS /fp:precise
/Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\\" /Fd"Debug\vc140.pdb" /Gd /TP
/analyze- /errorReport:queue -m32 -fmsc-version=1900 Main.cpp
clang-cl.exe : warning : argument unused during compilation: '/ZI' [ClangExcept.vcxproj]
clang-cl.exe : warning : argument unused during compilation: '/Gm' [ClangExcept.vcxproj]
clang-cl.exe : warning : argument unused during compilation: '/GS' [ClangExcept.vcxproj]
Main.cpp(7,3): error : cannot use 'throw' with exceptions disabled [ClangExcept.vcxproj]
throw 20;
^
Main.cpp(5,2): error : cannot use 'try' with exceptions disabled [ClangExcept.vcxproj]
try
^
2 errors generated.
According to this document, http://clang.llvm.org/docs/MSVCCompatibility.html: "Exceptions and SEH: Partial". But I can't make enough sense of it.
Has anyone been able to achieve this?