llvm / llvm/llvm-project

Clang should enable -fdiagnostics-color=auto for TERM=wezterm, similar to GCC

Open
#198,946 0 comments 1 reaction 0 assignees View on GitHub
clang
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## Summary

Clang does not emit colored diagnostics with `-fdiagnostics-color=auto` when `TERM=wezterm`, even though WezTerm supports ANSI colors and has a valid terminfo entry.

I would like Clang's auto color detection to behave more like GCC: if stderr is a TTY and `TERM` is set to something other than `dumb`, diagnostics should be colorized.

## Environment

```text
Ubuntu clang version 21.1.8 (6ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-21/bin
````

OS:

```text
Ubuntu 26.04
```

Terminal:

```text
WezTerm
TERM=wezterm
```

## Reproducer

```sh
cat > /tmp/clang-color-test.c <<'EOF'
int main() {
return unknown_symbol;
}
EOF

TERM=wezterm clang -fdiagnostics-color=auto /tmp/clang-color-test.c
```

## Actual behavior

With `TERM=wezterm`, Clang does not emit colored diagnostics:

```sh
TERM=wezterm clang -fdiagnostics-color=auto /tmp/clang-color-test.c
# no color
```

However, these do produce colored diagnostics:

```sh
TERM=tmux-256color clang -fdiagnostics-color=auto /tmp/clang-color-test.c
# color

TERM=wezterm-color clang -fdiagnostics-color=auto /tmp/clang-color-test.c
# color, even though wezterm-color is not a valid terminfo entry
```

GCC also emits colored diagnostics, as long as stderr is a TTY and `TERM` is not `dumb`:

```sh
TERM=wezterm gcc -fdiagnostics-color=auto /tmp/clang-color-test.c
# color
```

## Expected behavior

Clang should emit colored diagnostics for:

```sh
TERM=wezterm clang -fdiagnostics-color=auto /tmp/clang-color-test.c
```

when stderr is a TTY.

Ideally, Clang's `-fdiagnostics-color=auto` should use a rule similar to GCC:

* stderr is a TTY
* `TERM` is set
* `TERM != dumb`

This would avoid false negatives for modern terminals such as WezTerm.

## Additional information

The `wezterm` terminfo entry is installed and reports color support:

```sh
TERM=wezterm tput colors
# 256
```

The behavior suggests that Clang is using a hard-coded `TERM` name/pattern allowlist rather than checking whether the terminal can handle ANSI color escapes in practice.

This causes a false negative for `TERM=wezterm`, while a non-existent value such as `TERM=wezterm-color` enables color just because it matches the `*color` suffix pattern.

## Why GCC-like behavior would be preferable

GCC's behavior is more useful in practice here. It enables diagnostic colors in auto mode when stderr is a TTY and `TERM` is not `dumb`.

That avoids the need to maintain an ever-growing allowlist of terminal names such as:

* wezterm
* kitty
* alacritty
* ghostty
* future terminal emulators

If a user does not want colors, they can still use:

```sh
-fdiagnostics-color=never
```

or configure their environment accordingly.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the provided C program and TERM values, then trace Clang's handling of -fdiagnostics-color=auto and its terminal checks. The work is done when a TTY with TERM=wezterm produces colored diagnostics while TERM=dumb and explicit color disabling retain their expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.