-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[Clang] adjust caret placement for the suggested attribute location for enum class #168092
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
Open
a-tarasyuk
wants to merge
14
commits into
llvm:main
Choose a base branch
from
a-tarasyuk:fix/163224
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+84
−26
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
68dc4b9
[Clang] adjust caret placement for the suggested attribute location f…
a-tarasyuk 5152768
derive enum attribute locations from EnumDecl instead of Lexer
a-tarasyuk 9f93393
remove lambda
a-tarasyuk a495ee9
cleanup, add additional comment
a-tarasyuk 7bc4552
Merge branch 'main' into fix/163224
a-tarasyuk 303b91b
Merge branch 'main' into fix/163224
a-tarasyuk 782923b
use explicit type
a-tarasyuk 253af19
Merge branch 'fix/163224' of https://github.com/a-tarasyuk/llvm-proje…
a-tarasyuk f0f5dfd
Merge branch 'main' into fix/163224
a-tarasyuk 1f565db
Merge branch 'main' into fix/163224
a-tarasyuk a394503
Merge branch 'main' into fix/163224
a-tarasyuk 444bfc5
track enum key source range in EnumDecl
a-tarasyuk 55ab1a4
Merge branch 'main' of https://github.com/llvm/llvm-project into fix/…
a-tarasyuk 3b4f729
Merge branch 'fix/163224' of https://github.com/a-tarasyuk/llvm-proje…
a-tarasyuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // RUN: %clang_cc1 -fsyntax-only -verify %s | ||
| // RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s -strict-whitespace | ||
|
|
||
| [[nodiscard]] enum class E1 { }; | ||
| // expected-error@-1 {{misplaced attributes; expected attributes here}} | ||
| // CHECK: {{^}}{{\[\[}}nodiscard]] enum class E1 { }; | ||
| // CHECK: {{^}}~~~~~~~~~~~~~ ^ | ||
| // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:1-[[@LINE-4]]:15}:"" | ||
| // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:25-[[@LINE-5]]:25}:"{{\[\[}}nodiscard]]" | ||
|
|
||
| [[nodiscard]] enum struct E2 { }; | ||
| // expected-error@-1 {{misplaced attributes; expected attributes here}} | ||
| // CHECK: {{^}}{{\[\[}}nodiscard]] enum struct E2 { }; | ||
| // CHECK: {{^}}~~~~~~~~~~~~~ ^ | ||
| // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:1-[[@LINE-4]]:15}:"" | ||
| // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:26-[[@LINE-5]]:26}:"{{\[\[}}nodiscard]]" | ||
|
|
||
| [[nodiscard]] enum class E3 { }; | ||
| // expected-error@-1 {{misplaced attributes; expected attributes here}} | ||
| // CHECK: {{^}}{{\[\[}}nodiscard]] enum class E3 { }; | ||
| // CHECK: {{^}}~~~~~~~~~~~~~ ^ | ||
| // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:1-[[@LINE-4]]:15}:"" | ||
| // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:34-[[@LINE-5]]:34}:"{{\[\[}}nodiscard]]" | ||
|
|
||
| [[nodiscard]] enum /*comment*/ class E4 { }; | ||
| // expected-error@-1 {{misplaced attributes; expected attributes here}} | ||
| // CHECK: {{^}}{{\[\[}}nodiscard]] enum /*comment*/ class E4 { }; | ||
| // CHECK: {{^}}~~~~~~~~~~~~~ ^ | ||
| // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:1-[[@LINE-4]]:15}:"" | ||
| // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:38-[[@LINE-5]]:38}:"{{\[\[}}nodiscard]]" | ||
|
|
||
| [[nodiscard]] enum { A = 0 }; | ||
a-tarasyuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // expected-error@-1 {{misplaced attributes; expected attributes here}} | ||
| // CHECK: {{^}}{{\[\[}}nodiscard]] enum { A = 0 }; | ||
| // CHECK: {{^}}~~~~~~~~~~~~~ ^ | ||
| // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:1-[[@LINE-4]]:15}:"" | ||
| // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:19-[[@LINE-5]]:19}:"{{\[\[}}nodiscard]]" | ||
|
|
||
| namespace NS { | ||
| enum class E5; | ||
| } | ||
|
|
||
| [[nodiscard]] enum class NS::E5 { }; | ||
| // expected-error@-1 {{misplaced attributes; expected attributes here}} | ||
| // CHECK: {{^}}{{\[\[}}nodiscard]] enum class NS::E5 { }; | ||
| // CHECK: {{^}}~~~~~~~~~~~~~ ^ | ||
| // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:1-[[@LINE-4]]:15}:"" | ||
| // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:25-[[@LINE-5]]:25}:"{{\[\[}}nodiscard]]" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, the 'get location after the TST loc' logic works for all of these, right? With the exception being this is an enum class/enum struct?
Which, incidentially, doesn't actually work for enum class/enum struct? We potentially have OTHER tokens between the 'enum' and the 'class/struct' keywords (even if ill-formed potentially?), so in reality, if this is a scoped enum, we actually have to track down the class/struct token instead.
I find myself wondering if we should just have
EnumDeclstore the location of theclassinstead?Alternatively, and probably better than all of this:
Since we are at the semi-colon, we actually already KNOW the location for the enum insertion point, right? It is either 'the name' of the enum, or, if there is no identifier, it is the LBrace/semicolon location, right? All of which should be accessible from
ED. AND this should work whether or not it is scoped, right?I find myself wondering if we SHOULD be smarter about the OTHER cases as well, rather than a sizeof-keyword-offset funny business, since that also doesn't necessarily work if there are other tokens in the way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@erichkeane Thanks for the feedback. I had considered using the
identifierorlbracelocation, but I wasn’t sure whether placing the attribute directly before the name or the brace was acceptable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I THINK it is appropriate (identifier, lbrace, or semicolon)? I'm curious what @AaronBallman has to say.
Regarding the rest of the DeclSpec kinds, we could probably leave those alone + a fixme to 'get good' here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AaronBallman, whenever you have time, could you please review these changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My reading of the grammar is that the attribute can go after the key (so either
enumorenum class|struct), which I think is easier to reason about than what it can go before.Because "before" means more logic; there could be an optional nested name specifier. e.g., https://godbolt.org/z/eMo5T8r53 or there could be no name but an enum base, e.g., https://godbolt.org/z/jbqjnrn3d and so on.
So I think what makes the most sense is for
EnumDeclto track a source range for the enum key. So it'll either be a single token (enum) or it will be all of the tokens in the key (enum class). Then we can use the end of that range. Then the logic works regardless of whether the enum is scoped or not.WDYT?