[cfe-dev] [llvm-dev] problem (and fix) with -fms-extensions

Reid Kleckner via cfe-dev cfe-dev at lists.llvm.org
Thu May 18 09:49:17 PDT 2017


On Wed, May 17, 2017 at 4:35 PM, Marc Espie <espie at nerim.net> wrote:

> On Wed, May 17, 2017 at 03:55:06PM -0700, Reid Kleckner wrote:
> >
> >    On Wed, May 17, 2017 at 3:22 PM, Marc Espie <[1]espie at nerim.net>
> wrote:
> >
> >      On Wed, May 17, 2017 at 01:01:07PM -0700, Reid Kleckner wrote:
> >      >
> >      >Â  Â  I'd rather not add new pre-defined macros if we can avoid it.
> >      There are
> >      >Â  Â  already too many. You can probably detect this situation
> >      with:
> >      >Â  Â  #if defined(_MSC_EXTENSIONS) && !defined(_WCHAR_T_DEFINED)
> >      >
> >      Was this added recently ?
> >      There is no _MSC_EXTENSIONS in the clang I'm using...
> >
> >    Looks like we only define it for Windows targets.
> >    How about __is_identifier?
>
> Or, what's the problem with moving _MSC_EXTENSIONS to be for all targets.
>
>
> Look, this stuff is highly specific, I doubt many people are going to
> use -fms-extensions who don't know what they're doing.
> E.g., the exposure to _MSC_EXTENSIONS will be minimal.
>
> Having a single define will mean replacing (for us)
> #ifndef __cplusplus
> typedef int                     __wchar_t;
> #endif
>
> with
> #if !defined(__cplusplus) && !defined(_MSC_EXTENSIONS)
> typedef int                     __wchar_t;
> #endif
>
> which is fairly acceptable.
>
> Playing with __is_identifier is rather more awful, because there is no
> simple construct, we can't simply write:
> #if !defined(__cplusplus) || __is_identifier(__wchar_t)
> because  this *also* has to work with other compilers, some of which
> do not understand __is_identifier at all, so it can't be a single test
> then.
>
> It would become some atrocity like
>
> #if !defined(__cplusplus)
> # if defined(__is_identifier)
> #  if __is_identifier(__wchar_t)
> #  else
> typedef int     __wchar_t;
> #  endif
> # else
> typedef int     __wchar_t;
> # endif
> #endif
>
> And that has about zero chance to ever be committed in our tree,
> especially since this is in a md _types.h file, so this construct x10 times
> in the tree.
>

So, we actually have documentation on this, and __wchar_t is the example
use case:
https://clang.llvm.org/docs/LanguageExtensions.html#is-identifier

Please just use it, it works.

I do not want to define _MSC_EXTENSIONS more than we already do, and I
don't think we should add more pre-defined macros when we already have
these nicely factored feature test macros that don't pollute the global
namespace. The "simple solution" is not a good solution.

I believe our use of _MSC_EXTENSIONS is wrong anyway. It is controlled by
MSVC's /Ze and /Za flags, which do not relate to our -fms-extensions flag.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170518/c6e873e5/attachment.html>


More information about the cfe-dev mailing list