FIXIT hint displayed by TextDiagnosticPrinter should have different underline color for text being changed
| Bugzilla Link | 7141 |
| Version | trunk |
| OS | All |
| CC | @DougGregor |
Extended
Consider:
$ cat t.cpp
class Foo {
public:
int static myStaticMethod();
};
int test_foo() {
return Foo::myStaticMetho();
}
$ clang -fsyntax-only t.cpp
t.cpp:7:15: error: no member named 'myStaticMetho' in 'Foo'; did you mean 'myStaticMethod'?
return Foo::myStaticMetho();
~~~~~^~~~~~~~~~~~~
myStaticMethod
t.cpp:3:14: note: 'myStaticMethod' declared here
int static myStaticMethod();
^
1 error generated.
In this example Clang is suggesting a FIXIT for the misspelling of the member function in the call. While this text alone doesn't show it, the entire "~~~~~^~~~~~~~~~~~~" is color green, but this makes it look like the entire text is going to be replaced (which would be incorrect if that was the case, as it would drop the 'Foo::'). The FIXIT hint actually does the right thing by only replacing the 'myStaticMetho' text, but this isn't clear to the user.
To remedy this UI issue, we can have the color for the '~~~~~' under the part that is going to be changed a different color (or use a different squiggly character, e.g. '=').
Bisected: the reported behavior no longer reproduces starting with #117671 (https://github.com/llvm/llvm-project/commit/cc7fc9978fc8c9b8e1da2e283026feaf85807ea5).
Godbolt: https://godbolt.org/z/nM5E6545K
- Clang 20.1.0 (assertions): Underlines both
Foo::andmyStaticMethoalike - Clang 21.1.0 (assertions): Limits the underline to
myStaticMetho - Clang (assertions trunk): Limits the underline to
myStaticMetho
This is only an observed change in behavior. I have not checked whether #117671 addresses the cause of this report or only stops it from reproducing; whether that resolves the issue is up to the maintainers.
Prepared with assistance from Codex.