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



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to