Compiling Visual Studio 2017 headers with clang library

Hi,
I'm trying to resurrect an open source C++ reflection tool (https://github.com/Celtoys/clReflect ) against the latest clang. I've got everything building and the tool produces some output, though I've yet to analyse if the generated database is complete and correct.

I'm trying to build with Visual Studio 2017 on Windows 10.

I'm having a hard time getting the compiler settings correct to parse Microsoft's Visual C headers, as most documentation is relative to the command line.

First of all, what is the correct/official way to set lang_options.MSCompatibilityVersion? clang::LangOptions::MSVC2017 by itself doesn't seem to make a difference, one comment online seems to suggest a scale factor, though it is odd that I can't find a macro or constant for this.

I am getting
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/ucrt\stdio.h(378,9): warning : macro expansion producing 'defined' has undefined behavior
2> #if _CRT_INTERNAL_NONSTDC_NAMES"
which is supposedly fixed by "-Wno-expansion-to-defined", though "m_DiagnosticOptions.Warnings.push_back("no-expansion-to-defined");" doesn't seem to make a difference. While I can obviously fix my own code not to use undefined behaviour, I don't want to require a change to the standard C headers that come with Windows.

And I'm getting
"2>E:/External/clReflect/src/clReflectTest/clcppcodegen.cpp(211,7): warning : forward references to 'enum' types are a Microsoft extension
2> enum NoInit;"

I've got
" lang_options.MicrosoftExt = 1;
  lang_options.MSVCCompat = 1;
  lang_options.DeclSpecKeyword = 1;
"
are there any more options to enable Microsoft-specific extensions?

Cheers,
Jens

Hi,
I got this to work, so for the benefit of future people coming across this from Google:

I am getting
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/ucrt\stdio.h(378,9): warning : macro expansion producing 'defined' has undefined behavior
2> #if _CRT_INTERNAL_NONSTDC_NAMES"
which is supposedly fixed by "-Wno-expansion-to-defined", though "m_DiagnosticOptions.Warnings.push_back("no-expansion-to-defined");" doesn't seem to make a difference. While I can obviously fix my own code not to use undefined behaviour, I don't want to require a change to the standard C headers that come with Windows.

This was fixed by using the second form of createDiagnostics that takes DiagnosticOptions * as the first parameter and returns a DiagnosticsEngine. My code required some extra work to handle the lifetime of the various reference counted objects correctly, but now the warning is correctly suppressed.

And I'm getting
"2>E:/External/clReflect/src/clReflectTest/clcppcodegen.cpp(211,7): warning : forward references to 'enum' types are a Microsoft extension
2> enum NoInit;”

Somehow I had it in my head that I have to enable this extension, but apparently I have to silence the warning instead: “no-microsoft-enum-forward-reference”

Cheers,
Jens