Why doesn't clang use colors for diagnostics by default?

Hello, all.

Why doesn't clang use colors for diagnostics by default?
My environment:

$ cat /etc/*-release
Red Hat Enterprise Linux Server release 6.3 (Santiago)

$ echo $TERM
xterm

Doc here http://clang.llvm.org/docs/UsersManual.html#formatting-of-diagnostics says: "This option, which defaults to on when a color-capable terminal is detected". Isn't xterm "a color-capable terminal"?

If I give -fcolor-diagnostics explicitly, all works as expected. But why must I do that? GCC uses colors by default.

Are you invoking Clang with “clang foo.cc” or “clang -cc1 foo.cc”? The first should detect if you have a color capable terminal and automatically turn on color diagnostics while the second needs the flag explicitly. The other possibility is that the Clang you are using was compiled with the libraries needed to detect a color terminal, and defaults to no color.

I'm using command like this:

$ clang++ prg.cpp

My Clang is built from sources. What libraries it needs to use colors automatically? Or may be there is some option that I can specify for configure?

Hi Victor:

Try setting TERM to a color terminal, e.g., xterm-color or xterm-256color and see if that helps. I use xterm-256color inside tmux and it works fine.

hth…
don

No. Still no luck. Tried both

Did you build clang? Do you have terminfo installed? I think that’s what it checks.

Did you build clang?

Yes

Do you have terminfo installed?

$ find /usr/share/terminfo -type f
/usr/share/terminfo/k/kon2
/usr/share/terminfo/k/kon
/usr/share/terminfo/k/konsole-256color
/usr/share/terminfo/k/konsole
/usr/share/terminfo/v/vs100
/usr/share/terminfo/c/cygwin
/usr/share/terminfo/c/cons25
/usr/share/terminfo/t/teraterm2.3
/usr/share/terminfo/t/teraterm
/usr/share/terminfo/g/gnome
/usr/share/terminfo/g/gnome-256color
/usr/share/terminfo/w/wsvt25
/usr/share/terminfo/w/wsvt25m
/usr/share/terminfo/n/nxterm
/usr/share/terminfo/n/nsterm
/usr/share/terminfo/m/mrxvt
/usr/share/terminfo/m/mach
/usr/share/terminfo/m/mach-bold
/usr/share/terminfo/m/mach-color
/usr/share/terminfo/m/mlterm
/usr/share/terminfo/E/Eterm-88color
/usr/share/terminfo/E/Eterm-256color
/usr/share/terminfo/E/Eterm
/usr/share/terminfo/E/Eterm-color
/usr/share/terminfo/a/aterm
/usr/share/terminfo/a/ansis
/usr/share/terminfo/a/ansi80x25
/usr/share/terminfo/p/putty-vt100
/usr/share/terminfo/p/pcansi
/usr/share/terminfo/p/putty-256color
/usr/share/terminfo/p/putty
/usr/share/terminfo/s/screen.xterm-new
/usr/share/terminfo/s/sun
/usr/share/terminfo/s/screen-16color-bce
/usr/share/terminfo/s/screen-16color-s
/usr/share/terminfo/s/screen-16color-bce-s
/usr/share/terminfo/s/sun1
/usr/share/terminfo/s/screen
/usr/share/terminfo/s/screen.rxvt
/usr/share/terminfo/s/sun2
/usr/share/terminfo/s/screen.linux
/usr/share/terminfo/s/screen-256color-bce
/usr/share/terminfo/s/screen-16color
/usr/share/terminfo/s/screen-256color-s
/usr/share/terminfo/s/screen.xterm-xfree86
/usr/share/terminfo/s/screen-256color-bce-s
/usr/share/terminfo/s/screen.teraterm
/usr/share/terminfo/s/screen-bce
/usr/share/terminfo/s/screen-s
/usr/share/terminfo/s/screen.mlterm
/usr/share/terminfo/s/screen-w
/usr/share/terminfo/s/screen.xterm-r6
/usr/share/terminfo/s/screen-256color
/usr/share/terminfo/s/screen.Eterm
/usr/share/terminfo/j/jfbterm
/usr/share/terminfo/h/hurd
/usr/share/terminfo/r/rxvt-color
/usr/share/terminfo/r/rxvt-xpm
/usr/share/terminfo/r/rxvt-unicode
/usr/share/terminfo/r/rxvt-basic
/usr/share/terminfo/r/rxvt
/usr/share/terminfo/r/rxvt-88color
/usr/share/terminfo/r/rxvt-16color
/usr/share/terminfo/r/rxvt-cygwin-native
/usr/share/terminfo/r/rxvt-256color
/usr/share/terminfo/r/rxvt-cygwin
/usr/share/terminfo/x/xterm-xf86-v32
/usr/share/terminfo/x/xterm-xi
/usr/share/terminfo/x/xterm-r5
/usr/share/terminfo/x/xterm-vt220
/usr/share/terminfo/x/xterm-new
/usr/share/terminfo/x/xterm-sun
/usr/share/terminfo/x/xterm-nic
/usr/share/terminfo/x/xterm-8bit
/usr/share/terminfo/x/xterm-old
/usr/share/terminfo/x/xterm-hp
/usr/share/terminfo/x/xterm-color
/usr/share/terminfo/x/xterm-256color
/usr/share/terminfo/x/xterm-pcolor
/usr/share/terminfo/x/xterm-basic
/usr/share/terminfo/x/xterm-noapp
/usr/share/terminfo/x/xterm-24
/usr/share/terminfo/x/xterm-bold
/usr/share/terminfo/x/xterms
/usr/share/terminfo/x/xterm
/usr/share/terminfo/x/xterm-1003
/usr/share/terminfo/x/xterm-sco
/usr/share/terminfo/x/xterm-1002
/usr/share/terminfo/x/xterm-vt52
/usr/share/terminfo/x/xterm-16color
/usr/share/terminfo/x/xterm-r6
/usr/share/terminfo/x/xterm-xf86-v44
/usr/share/terminfo/x/xfce
/usr/share/terminfo/x/xterm-xf86-v333
/usr/share/terminfo/x/xterm-88color
/usr/share/terminfo/x/xterm-xfree86
/usr/share/terminfo/x/xterm-xf86-v43
/usr/share/terminfo/x/xterm-xf86-v40
/usr/share/terminfo/x/xterm-xf86-v33
/usr/share/terminfo/e/eterm
/usr/share/terminfo/e/eterm-color
/usr/share/terminfo/A/Apple_Terminal

I meant the headers. If you use cmake, take a look at cmake/config-ix.cmake. Configure does something similar.

Basically, if it finds the right headers, it will #define HAS_TERMINFO, and the code that checks it is terminalHasColors() in lib/Support/Unix/Process.inc.

Not sure how gcc checks.

Actually, I just looked at the cmake code and it checks a list of libraries, i.e., tinfo, terminfo, curses, ncurses, and ncursesw. If any of them have setupterm, it will define HAVE_TERMINFO 1.

So, at least that give you something to check.

hth…
don

Yes, HAVE_TERMINFO was undefined. I installed ncurses-devel package (before rebuilding) and now it works as expected.
Thank you very much!