-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
clang-format interpreting variable name interface
as some kind of keyword and changes formatting in constructor delegation
#53173
Comments
@llvm/issue-subscribers-clang-format |
@llvm/issue-subscribers-bug |
This is exactly what you'd get for any keyword. won't be treated any different from any other keyword (because its no longer a tok::identifier) This is because interface is a keyword of at least Java & C# i.e.
Could we fix it, yes, would we with any priority...... patches welcome |
Problem solved... ;-)
|
That said, actually the following is all that's effectively needed
let me make the review and we can discuss it. (I'd have to look at whats not covered by isCpp() i.e. that might have an impact on ObjectiveC/ObjectiveC++) |
As far as this indeed works for this case, I'd rather look for a more generic solution rather than specialized one like this. I was thinking about maintaining the list of keywords for given language and check whether given word is a keyword in present context. This doesn't sound like tons of effort however I'm not familiar with the code base. Gonna give this a try as well |
Okay, I pass on this one. I wanted to go with something like: // clang/include/clang/Lex/Token.h
bool is(tok::TokenKind K, llvm::clang::format::FormatStyle::LanguageKind L) const {
/*... here I'd check if K is in extraTokens and L is in langs that have extraTokens and return is(TokenKind K) only if both or none of those are true ...*/
} however I'm kinda not enjoying writing this and going through not PR process, so I leave this as is. It's been already fixed by renaming on our side also and is not important from what I understand |
This is not really an exhaustive solution, as it still can confuse C# with Javascript, however the meat of the code for this is already written. |
I don't believe a generalised solution is required here, this is a corner case and one that in my view should be dealt with as a corner case The reality is if we presented code like this using interface as a variable name i personally would reject it during code review. Whilst we want clang-format to be 100% correct it cannot be without semantic information and I for one don't want clang format to need compiler flags in order to understand what people using macros or common language keywords as variables really meant when they could easily change their ways and be good! We do already have keyword lists but I think if we made a sudden change to is/isNot like this we'd break the world Also remember objc uses interface and that code can be in a .h file so even this suggested change could in theory be wrong |
If you are looking to make the simple change I suggested as a good first issue I am happy to lead you through the patch process of adding tests etc |
@llvm/issue-subscribers-good-first-issue |
For reference, the above mentioned patch is applied to: llvm-project/clang/lib/Format/UnwrappedLineParser.cpp Lines 2010 to 2014 in 1522a3b
IIUC, this probably fine since other llvm-project/clang/lib/Format/UnwrappedLineParser.cpp Lines 1756 to 1757 in 1522a3b
llvm-project/clang/lib/Format/UnwrappedLineParser.cpp Lines 1977 to 1978 in 1522a3b
|
… C++ Fixes llvm#53173. Differential Revision: https://reviews.llvm.org/D148437
Hi,
as in title, I have clang in version 13.0, on 12.0.1 the issue does not exist.
Here is a minimal example:
I've included it here: https://github.com/Zwo1in/clang-format-interface-reproduction
The text was updated successfully, but these errors were encountered: