Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing typo correction diagnostic in preprocessor conditionals #51598

Closed
AaronBallman opened this issue Oct 21, 2021 · 2 comments
Closed

Missing typo correction diagnostic in preprocessor conditionals #51598

AaronBallman opened this issue Oct 21, 2021 · 2 comments
Labels
bugzilla Issues migrated from bugzilla c23 clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer enhancement Improving things as opposed to bug fixing, e.g. new or missing feature

Comments

@AaronBallman
Copy link
Collaborator

Bugzilla Link 52256
Version trunk
OS Windows NT
CC @zygoloid

Extended Description

Consider the following code, and assume that FOO is not defined:

#ifdef FOO
#elfidef BAR
#endif

In this case, we do not issue any diagnostic about the typo where #elifdef is misspelled as #elfidef because it appears within a preprocessor branch that is discarded.

When scanning for the end of the discarded block, we should consider typo corrections for non-directives to help catch this sort of mistake.

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Oct 21, 2021

We should be a little careful here. It's not unreasonable for people to write

#if special_compiler
#special_compiler_directive
#endif

I think it would be reasonable to warn by default on typos where the correction is to #if/#ifdef/#ifndef/#elif/#elifdef/#elifndef/#else/#endif, but not corrections to any other directive. (We can't produce an error, because such inputs are valid.)

@AaronBallman
Copy link
Collaborator Author

Agreed that we need to be careful. FWIW, what raised the issue for me was when I tested the behavior of #elifdef/#elifndef in older Clang versions and I was... a bit surprised: https://godbolt.org/z/8Wdx5d9of

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@Quuxplusone Quuxplusone added the clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer label Jan 17, 2022
@AaronBallman AaronBallman added the enhancement Improving things as opposed to bug fixing, e.g. new or missing feature label Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c23 clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer enhancement Improving things as opposed to bug fixing, e.g. new or missing feature
Projects
None yet
Development

No branches or pull requests

2 participants