Search code examples
c++windowsmingwclrtype-safety

Does mingw support clr safe?


I'm wanting to compile C++ extensions to SQL Server, from the docs

Safe mode: Run verifiably typesafe code; compiled with /clr:safe.

Does mingw's C++ compile support /clr:safe?


Solution

  • The Common Language Runtime (CLR) of the Microsoft .NET framework has no application to non-Microsoft, non-.NET compilers. The several Windows ports of GCC that can be meant by "mingw" are all non-.NET, native compilers. Microsoft's managed C++-like language, C++/CLI, to which /clr:safe applies, isn't C++.

    /clr:safe directs the Microsoft compiler to generate an output file that contains no native code, only verifiably typesafe Microsoft Intermediate Language code for managed execution with the CLR. By definition a native compiler cannot provide an equivalent option: generating native code is what they do.

    If what you are after is how to compile C++ with the strictest diagnostics GCC can provide, a diligent answer would be off-puttingly long, since there is a plethora of options for diagnosing corner cases of safety. Settle at least on:

    -Wall -Wextra -pedantic
    

    (see 3.8 Options to Request or Suppress Warnings) and perhaps augment the list as prompted by bitter exerience and mounting paranoia ;)

    Beyond the regular static diagnostics another level of hygeine is available through the large -fsanitize=... family of the 3.11 Program Instrumentation Options.