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

Douglas Gregor dgregor at apple.com
Sun Aug 8 13:07:42 PDT 2010



Sent from my iPhone

On Aug 8, 2010, at 9:34 AM, Francois Pichet <pichet2000 at gmail.com> wrote:

> 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.

What types are involved? This may be a symptom of a different incompatibility  in the type system. 

> 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)

We sometimes downgrade errors to warnings when other compilers fail to diagnose a particular conformance issue. We can consider that here. 

> 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.

This could/should be implemented under -fms-extensions. 

> 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.

Is it truly undeclared, or is it some kind of magic type? The former is very hard to deal with. 

> 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?

Bugs or extension requests, yes. Please include something like [Microsoft] in the title so we can keep them separate from other bugs. 



More information about the cfe-dev mailing list