[cfe-dev] CLang compiling windows.h from the Windows SDK

Francois Pichet pichet2000 at gmail.com
Sun Aug 8 06:34:20 PDT 2010


Hi,

Read this if you are interested in CLang compatibility with MSVC.

Today I did some testing compiling just <windows.h> in C and C++ mode
using CLang.  (Let's forget MFC)
Note that including <windows.h> pulls close to 80000 lines of C/C++ declaration.
I used the <Windows.h> bundled with Visual Studio 2008 (SDK v7.0A).
BTW the <Windows.h> coming with the MinGW package is compiling fine
but that's to be expected I think.

I created a file "test.c" containing just 1 line:
#include "Windows.h"

Then I compiled in C mode and C++ mode using
clang -I"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include"
-D_MSC_VER=1500 -Wno-missing-declarations -Wno-invalid-token-paste
-Wno-unused-value -x c test.c
and
clang -I"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include"
-D_MSC_VER=1500 -Wno-missing-declarations -Wno-invalid-token-paste
-Wno-unused-value -x c++ test.c

_MSC_VER=1500 emulate MSVC 2008.


In C mode there are only 2 kinds of error:
1- MSVC allows typedef redefinition with a different type, CLang doesn't.
2- CLang flags this as a error:
            typedef struct tagPROPVARIANT PROPVARIANT;
            void foo(PROPVARIANT a[]);         <====== array has
incomplete element type 'PROPVARIANT'
(both cl.exe and gcc.exe accepts foo prototype, note that
tagPROPVARIANT is actually undefined at this point)


In C++ mode there are only 3 kinds of error:
1- MSVC allows typedef redefinition with a different type, CLang
doesn't. (same thing as in C mode)
2- CLang doesn't recognize the __uuidof operator.
3. CLang doesn't like:
     template<typename T> void** IID_PPV_ARGS_Helper(T** pp)
     {
        static_cast<IUnknown*>(*pp);            <=== clang error:
unknown type name 'IUnknown'
        return reinterpret_cast<void**>(pp);
     }
Note that 'IUnknown' is actually undefined at this point but MSVC accept it.


CLang is actually very close to be able to handle the core Windows
system headers as provided by Microsoft.
Should I report these as bugs?
Is CLang being able to parse the Windows SDKs core headers a worthwhile goal?



More information about the cfe-dev mailing list