Skip to content

Commit 5152768

Browse files
committed
derive enum attribute locations from EnumDecl instead of Lexer
1 parent 68dc4b9 commit 5152768

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

clang/lib/Parse/Parser.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,14 +1107,13 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal(
11071107

11081108
if (TKind == DeclSpec::TST_enum) {
11091109
const auto *ED = dyn_cast_or_null<EnumDecl>(DS.getRepAsDecl());
1110-
if (ED && ED->isScoped()) {
1111-
const auto &SM = Actions.getSourceManager();
1112-
const auto &LangOpts = Actions.getLangOpts();
1113-
auto End = Lexer::getLocForEndOfToken(DS.getTypeSpecTypeLoc(),
1114-
/*Offset*/ 0, SM, LangOpts);
1115-
auto NextToken = Lexer::findNextToken(End, SM, LangOpts);
1116-
if (NextToken)
1117-
return NextToken->getEndLoc();
1110+
if (ED) {
1111+
if (ED->isScoped() && ED->getIdentifier())
1112+
return ED->getLocation();
1113+
1114+
const auto Begin = ED->getBraceRange().getBegin();
1115+
if (Begin.isValid())
1116+
return Begin;
11181117
}
11191118
}
11201119

clang/test/FixIt/fixit-cxx0x-attributes.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,34 @@
44
[[nodiscard]] enum class E1 { };
55
// expected-error@-1 {{misplaced attributes; expected attributes here}}
66
// CHECK: {{^}}{{\[\[}}nodiscard]] enum class E1 { };
7-
// CHECK: {{^}}~~~~~~~~~~~~~ ^
7+
// CHECK: {{^}}~~~~~~~~~~~~~ ^
88
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:1-[[@LINE-4]]:15}:""
9-
// CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:25-[[@LINE-5]]:25}:"{{\[\[}}nodiscard]]"
9+
// CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:26-[[@LINE-5]]:26}:"{{\[\[}}nodiscard]]"
1010

1111
[[nodiscard]] enum struct E2 { };
1212
// expected-error@-1 {{misplaced attributes; expected attributes here}}
1313
// CHECK: {{^}}{{\[\[}}nodiscard]] enum struct E2 { };
14-
// CHECK: {{^}}~~~~~~~~~~~~~ ^
14+
// CHECK: {{^}}~~~~~~~~~~~~~ ^
1515
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:1-[[@LINE-4]]:15}:""
16-
// CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:26-[[@LINE-5]]:26}:"{{\[\[}}nodiscard]]"
16+
// CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:27-[[@LINE-5]]:27}:"{{\[\[}}nodiscard]]"
1717

1818
[[nodiscard]] enum class E3 { };
1919
// expected-error@-1 {{misplaced attributes; expected attributes here}}
2020
// CHECK: {{^}}{{\[\[}}nodiscard]] enum class E3 { };
21-
// CHECK: {{^}}~~~~~~~~~~~~~ ^
21+
// CHECK: {{^}}~~~~~~~~~~~~~ ^
2222
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:1-[[@LINE-4]]:15}:""
23-
// CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:34-[[@LINE-5]]:34}:"{{\[\[}}nodiscard]]"
23+
// CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:35-[[@LINE-5]]:35}:"{{\[\[}}nodiscard]]"
2424

2525
[[nodiscard]] enum /*comment*/ class E4 { };
2626
// expected-error@-1 {{misplaced attributes; expected attributes here}}
2727
// CHECK: {{^}}{{\[\[}}nodiscard]] enum /*comment*/ class E4 { };
28-
// CHECK: {{^}}~~~~~~~~~~~~~ ^
28+
// CHECK: {{^}}~~~~~~~~~~~~~ ^
29+
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:1-[[@LINE-4]]:15}:""
30+
// CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:39-[[@LINE-5]]:39}:"{{\[\[}}nodiscard]]"
31+
32+
[[nodiscard]] enum { A = 0 };
33+
// expected-error@-1 {{misplaced attributes; expected attributes here}}
34+
// CHECK: {{^}}{{\[\[}}nodiscard]] enum { A = 0 };
35+
// CHECK: {{^}}~~~~~~~~~~~~~ ^
2936
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:1-[[@LINE-4]]:15}:""
30-
// CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:38-[[@LINE-5]]:38}:"{{\[\[}}nodiscard]]"
37+
// CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:20-[[@LINE-5]]:20}:"{{\[\[}}nodiscard]]"

0 commit comments

Comments
 (0)