[PATCH] D51011: [Preprocessor] raise gcc compatibility macros.

Eli Friedman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 21 15:06:31 PDT 2018


efriedma added a comment.

I'd suggest something like this, if you really need to detect the compiler:

  #if defined(__clang__)
  // clang
  #elif defined(__INTEL_COMPILER)
  // icc
  #elif defined(__GNUC__)
  // gcc
  #else
  #error "Unknown compiler"
  #endif



> Regarding the glibc headers, do you know why glibc doesn't just add code for __clang__ rather than Clang (and ICC) claim to be a gcc compatible to a point compiler?

clang pretends to be gcc 4.2 because that was the simplest way to make a lot of existing code work, at the time clang was written. clang supports almost all the language extensions supported by that version of gcc, so code was more likely to work if clang pretended to be gcc, rather than some unknown compiler.  And now, it would break a bunch of code if it changed, so it basically can't be changed.  This is similar to the history of web browser user agent strings.

For new code, we encourage users to use the feature checking macros (https://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros ), rather than checking for specific compiler versions, where possible.


Repository:
  rC Clang

https://reviews.llvm.org/D51011





More information about the cfe-commits mailing list