This seems like a pretty safe case, and common enough to be useful.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
| clang-tools-extra/clangd/Diagnostics.cpp | ||
|---|---|---|
| 563 | I feel a bit nervous about this (even it is for macro-arg expansion only), as macro is very tricky. I think we may result in invalid code after applying the fixits in some cases:
#define LA(arg1, arg2) [arg1, arg2] { return arg2;}
void test1(int x, int y) {
LA(x, y); // after fixit, it would become LA(, y)? or LA(y)
}
void f1(int &a);
void f2(int *a) {
f1(a); // clang will emits a diagnostic with a fixit adding preceding a `*` to a.
}maybe we should be more conservative? just whitelist some diagnostics? fixing typos seems pretty safe. | |
| clang-tools-extra/clangd/Diagnostics.cpp | ||
|---|---|---|
| 563 | your test1 example doesn't trigger this case because the fix has to delete a comma that's provided by the macro body - this patch doesn't change behavior. To construct an example that follows this schema: struct S { S(int *x); };
int *x;
S s1(*x); // fixit -> S s1(x);
#define CONCAT(a,b) a b
S s2(CONCAT(*, x)); // fixit -> S s2(CONCAT(, x));The fixed code compiles fine and addresses the error in the expected way. It may not be *idiomatic*, but this is also a pathological case. I think it's at least as good to offer the fix in this case, and certainly it's not a good reason to drop support for others..
I can't follow this example, there are no macros?
I think this leaves a lot of value on the table - we've been conservative so far. (To put this another way: by being too aggressive we'll get more feedback, by being more conservative we'll continue to get none) | |
| clang-tools-extra/clangd/Diagnostics.cpp | ||
|---|---|---|
| 563 |
ah, you are right.
sorry, the example was incomplete, the case is like int f1(int &a);
#define ABC(x) *x + f1(x);
void f2(int *a) {
ABC(a); // fixit -> ABC(*a), incorrect for the `*x` in macro body.
}if the macro argument is being used in multiple places of the macro body, it probably leads to problems. I suspect this is common in practice, we should not allow fixit in this case.
fair enough. | |
| clang-tools-extra/clangd/Diagnostics.cpp | ||
|---|---|---|
| 563 |
This is definitely true. As discussed offline, this is mitigated by:
Agreed to do it anyway and wait for feedback, I'll document this though. | |
I feel a bit nervous about this (even it is for macro-arg expansion only), as macro is very tricky.
I think we may result in invalid code after applying the fixits in some cases:
#define LA(arg1, arg2) [arg1, arg2] { return arg2;} void test1(int x, int y) { LA(x, y); // after fixit, it would become LA(, y)? or LA(y) }void f1(int &a); void f2(int *a) { f1(a); // clang will emits a diagnostic with a fixit adding preceding a `*` to a. }maybe we should be more conservative? just whitelist some diagnostics? fixing typos seems pretty safe.