[cfe-commits] [patch] Let clang parse typeid() on windows if _HAS_EXCEPTIONS is defined to 0

John McCall rjmccall at apple.com
Thu Apr 26 09:18:51 PDT 2012


On Apr 24, 2012, at 7:38 PM, Nico Weber wrote:
> if _HAS_EXCEPTIONS is set to 0, typeid() can't be used in clang on
> windows. One use case where this happens is ICU in chromium:
> http://git.chromium.org/gitweb/?p=chromium/deps/icu46.git;a=commitdiff_plain;h=8ad988882c0a6bb2ac66eecab662141110840e66
> 
> This is a reduced reproduction that builds fine with MSVC:
> 
> #define _HAS_EXCEPTIONS 0
> #include <exception>
> #include <typeinfo> // for typeid to work.
> 
> void f() {
>  (void)typeid(int);  // just typeid
> }
> 
> clang on the other hand complains about typeid requiring an include
> for <typeinfo>. That's because clang tries to look up std::type_info,
> and the MS typeinfo header apparently doesn't define type_info in the
> std namespace, but only if _HAS_EXCEPTIONS is defined to 0. The
> attached patch lets clang look up type_info in the global namespace in
> ms compat mode if the lookup for std::type-info fails.

That's a pretty awesome header bug.  Have you verified that MSVC
actually produces a value of type 'const ::type_info &', rather than (say)
implicitly forward-declaring std::type_info?

Also, please add a comment describing this problem in the code,
and make the testcase something like
MicrosoftCompatibilityNoExceptions.cpp so that we can reasonably
put other things in there.

John.



More information about the cfe-commits mailing list