I definitely don't want __GNUC__ defined in MS compat mode.  I also have code (some of it in open source libraries) that would have a conflict here.<br><br>I imagine there are different use cases.  My use case is that I want to be able to use clang to parse, traverse and rewrite my code in a one-off fashion, but ultimately will still be using MSVC to build.  I really don't want to have to make manual compensating changes (many of them in open source libraries) across thousands of files, in order to be able to use clang to make automatic changes across thousands of files.<br>
<br>Jay<br><br><div class="gmail_quote">On Tue, Mar 6, 2012 at 8:31 AM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On Mon, Mar 5, 2012 at 10:32 PM, Douglas Gregor <<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>> wrote:<br>
><br>
> On Mar 2, 2012, at 4:16 PM, Aaron Ballman wrote:<br>
><br>
>> There are a lot of references on the web which relate __GNUC__ to GCC<br>
>> for compiler discovery<br>
>> (<<a href="http://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers#GCC_C.2FC.2B.2B" target="_blank">http://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers#GCC_C.2FC.2B.2B</a>>,<br>

>> <<a href="http://www.ocf.berkeley.edu/%7Epad/tigcc/doc/html/cpp_SEC15_GNUC.html" target="_blank">http://www.ocf.berkeley.edu/~pad/tigcc/doc/html/cpp_SEC15_GNUC.html</a>>,<br>
>> etc).  This translates into a fair number of cross-compiler projects<br>
>> with code like this:<br>
>><br>
>> #if defined(__GNUC__)<br>
>>  // Do GCC things<br>
>> #elif defined(_MSC_VER)<br>
>>  // Do MSVC things<br>
>> ...<br>
>> #endif<br>
>><br>
>> This currently leads to problems when compiling with Clang because<br>
>> __GNUC__ (and friends) are always defined, even when compiling for MS<br>
>> compatibility (PR 11790).  I've attached a patch which addresses this<br>
>> by only defining __GNUC__ et al when MSVC mode is not set.  This means<br>
>> code like the above will work as expected.<br>
>><br>
>> Thoughts?<br>
><br>
> -  // Currently claim to be compatible with GCC 4.2.1-5621.<br>
> -  Builder.defineMacro("__GNUC_MINOR__", "2");<br>
> -  Builder.defineMacro("__GNUC_PATCHLEVEL__", "1");<br>
> -  Builder.defineMacro("__GNUC__", "4");<br>
> -  Builder.defineMacro("__GXX_ABI_VERSION", "1002");<br>
> +  if (!LangOpts.MSCVersion) {<br>
><br>
> This should probably just check LangOpts.MicrosoftMode.<br>
><br>
> I'm not sure about the general approach, though. Even when compiling in Microsoft-compatible mode, Clang is still much more GCC-like than MSVC-like. I would venture a guess that<br>
><br>
>        // Do GCC things<br>
><br>
> is far more likely to be standards-conforming code that Clang will accept than<br>
><br>
>        // Do MSVC things<br>
><br>
> especially when dealing with template libraries in C++.<br>
<br>
</div></div>I think your guess may be off base.  A lot of those things are<br>
includes.  At work, we have several sources like:<br>
<br>
#if defined( _MSC_VER )<br>
#include <Windows.h><br>
#elif defined( __GNUC__ )<br>
#include <gtk/gtk.h><br>
#endif<br>
<br>
I think the correct thing to do is define __clang__ and MSVC in<br>
MS-compat mode, like we already do for __clang__ and __GNUC__ for GNU<br>
mode.  It seems like a reasonable pattern.  If someone cares about<br>
clang, that's turned on appropriately, as is the compiler they're<br>
emulating.<br>
<br>
But I do wonder what should happen with -std=gnu++98<br>
-fms-compatibility as a combination.  Seems almost like an error?<br>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br>