[clang] [clang][Sema] Add diagnostic note for reference of function-like macros requiring without parentheses (PR #123495)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 12 07:15:37 PST 2025
AaronBallman wrote:
> > Also, i see the typo correction is unpredictable as I addressed above, is that a expected behaviour?
>
> @AaronBallman could you help me with this? I do understand the delayed typo thing but how is that being decided? also, I couldn't find that documented.
For this:
```
#define FOO1()
void f() {
int FOO;
int x = FOO1; // Typo correction to 'FOO' instead of note about 'FOO1()'.
}
```
I believe the issue is because the `CorrectionCandidateCallback` used is unaware of macro identifiers (because macros are not declarations and are replaced entirely by the time we get to the parser or sema). For example, we don't suggest a correction for this:
```
#define FOO1 12
int x = FOO;
```
https://godbolt.org/z/99s8P3vzc
but we do suggest a correction for this:
```
int FOO1 = 12;
int x = FOO;
```
https://godbolt.org/z/v94rjhxY4
I think it will be challenging to support macros in general because we'd have to be able to handle `#undef` removing macros that were previously defined, etc. I think for right now, it's fine to not have a typo correction.
https://github.com/llvm/llvm-project/pull/123495
More information about the cfe-commits
mailing list