forked from OSchip/llvm-project
Record correct source range for defaulted/deleted members.
Fixes https://llvm.org/bugs/show_bug.cgi?id=20744 struct A { A() = default; }; Previously the source range of the declaration of A ended at the ')'. It should include the '= default' part as well. The same for '= delete'. Note: this will break one of the clang-tidy fixers, which is going to be addessed in a follow-up patch. Differential Revision: http://reviews.llvm.org/D8465 llvm-svn: 233028
This commit is contained in:
parent
f2b408c64e
commit
5f4d76efd3
|
@ -71,17 +71,24 @@ NamedDecl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS,
|
|||
|
||||
bool Delete = false;
|
||||
SourceLocation KWLoc;
|
||||
SourceLocation KWEndLoc = Tok.getEndLoc().getLocWithOffset(-1);
|
||||
if (TryConsumeToken(tok::kw_delete, KWLoc)) {
|
||||
Diag(KWLoc, getLangOpts().CPlusPlus11
|
||||
? diag::warn_cxx98_compat_deleted_function
|
||||
: diag::ext_deleted_function);
|
||||
Actions.SetDeclDeleted(FnD, KWLoc);
|
||||
Delete = true;
|
||||
if (auto *DeclAsFunction = dyn_cast<FunctionDecl>(FnD)) {
|
||||
DeclAsFunction->setRangeEnd(KWEndLoc);
|
||||
}
|
||||
} else if (TryConsumeToken(tok::kw_default, KWLoc)) {
|
||||
Diag(KWLoc, getLangOpts().CPlusPlus11
|
||||
? diag::warn_cxx98_compat_defaulted_function
|
||||
: diag::ext_defaulted_function);
|
||||
Actions.SetDeclDefaulted(FnD, KWLoc);
|
||||
if (auto *DeclAsFunction = dyn_cast<FunctionDecl>(FnD)) {
|
||||
DeclAsFunction->setRangeEnd(KWEndLoc);
|
||||
}
|
||||
} else {
|
||||
llvm_unreachable("function definition after = not 'delete' or 'default'");
|
||||
}
|
||||
|
|
|
@ -2458,12 +2458,12 @@ namespace PR17746 {
|
|||
// CHECK-NEXT: <array>
|
||||
// CHECK-NEXT: <dict>
|
||||
// CHECK-NEXT: <key>line</key><integer>105</integer>
|
||||
// CHECK-NEXT: <key>col</key><integer>53</integer>
|
||||
// CHECK-NEXT: <key>col</key><integer>63</integer>
|
||||
// CHECK-NEXT: <key>file</key><integer>0</integer>
|
||||
// CHECK-NEXT: </dict>
|
||||
// CHECK-NEXT: <dict>
|
||||
// CHECK-NEXT: <key>line</key><integer>105</integer>
|
||||
// CHECK-NEXT: <key>col</key><integer>53</integer>
|
||||
// CHECK-NEXT: <key>col</key><integer>63</integer>
|
||||
// CHECK-NEXT: <key>file</key><integer>0</integer>
|
||||
// CHECK-NEXT: </dict>
|
||||
// CHECK-NEXT: </array>
|
||||
|
@ -2475,7 +2475,7 @@ namespace PR17746 {
|
|||
// CHECK-NEXT: <key>location</key>
|
||||
// CHECK-NEXT: <dict>
|
||||
// CHECK-NEXT: <key>line</key><integer>105</integer>
|
||||
// CHECK-NEXT: <key>col</key><integer>53</integer>
|
||||
// CHECK-NEXT: <key>col</key><integer>63</integer>
|
||||
// CHECK-NEXT: <key>file</key><integer>0</integer>
|
||||
// CHECK-NEXT: </dict>
|
||||
// CHECK-NEXT: <key>ranges</key>
|
||||
|
@ -2483,12 +2483,12 @@ namespace PR17746 {
|
|||
// CHECK-NEXT: <array>
|
||||
// CHECK-NEXT: <dict>
|
||||
// CHECK-NEXT: <key>line</key><integer>105</integer>
|
||||
// CHECK-NEXT: <key>col</key><integer>53</integer>
|
||||
// CHECK-NEXT: <key>col</key><integer>63</integer>
|
||||
// CHECK-NEXT: <key>file</key><integer>0</integer>
|
||||
// CHECK-NEXT: </dict>
|
||||
// CHECK-NEXT: <dict>
|
||||
// CHECK-NEXT: <key>line</key><integer>105</integer>
|
||||
// CHECK-NEXT: <key>col</key><integer>53</integer>
|
||||
// CHECK-NEXT: <key>col</key><integer>63</integer>
|
||||
// CHECK-NEXT: <key>file</key><integer>0</integer>
|
||||
// CHECK-NEXT: </dict>
|
||||
// CHECK-NEXT: </array>
|
||||
|
|
|
@ -139,7 +139,6 @@ class TestCXXDestructorDecl {
|
|||
// CHECK-NEXT: CompoundStmt
|
||||
|
||||
// Test that the range of a defaulted members is computed correctly.
|
||||
// FIXME: This should include the "= default".
|
||||
class TestMemberRanges {
|
||||
public:
|
||||
TestMemberRanges() = default;
|
||||
|
@ -156,12 +155,12 @@ void SomeFunction() {
|
|||
A = static_cast<TestMemberRanges &&>(B);
|
||||
TestMemberRanges C(static_cast<TestMemberRanges &&>(A));
|
||||
}
|
||||
// CHECK: CXXConstructorDecl{{.*}} <line:{{.*}}:3, col:20>
|
||||
// CHECK: CXXConstructorDecl{{.*}} <line:{{.*}}:3, col:49>
|
||||
// CHECK: CXXConstructorDecl{{.*}} <line:{{.*}}:3, col:44>
|
||||
// CHECK: CXXDestructorDecl{{.*}} <line:{{.*}}:3, col:21>
|
||||
// CHECK: CXXMethodDecl{{.*}} <line:{{.*}}:3, col:60>
|
||||
// CHECK: CXXMethodDecl{{.*}} <line:{{.*}}:3, col:55>
|
||||
// CHECK: CXXConstructorDecl{{.*}} <line:{{.*}}:3, col:30>
|
||||
// CHECK: CXXConstructorDecl{{.*}} <line:{{.*}}:3, col:59>
|
||||
// CHECK: CXXConstructorDecl{{.*}} <line:{{.*}}:3, col:54>
|
||||
// CHECK: CXXDestructorDecl{{.*}} <line:{{.*}}:3, col:31>
|
||||
// CHECK: CXXMethodDecl{{.*}} <line:{{.*}}:3, col:70>
|
||||
// CHECK: CXXMethodDecl{{.*}} <line:{{.*}}:3, col:65>
|
||||
|
||||
class TestCXXConversionDecl {
|
||||
operator int() { return 0; }
|
||||
|
|
|
@ -122,6 +122,18 @@ TEST(CXXConstructorDecl, NoRetFunTypeLocRange) {
|
|||
EXPECT_TRUE(Verifier.match("class C { C(); };", functionDecl()));
|
||||
}
|
||||
|
||||
TEST(CXXConstructorDecl, DefaultedCtorLocRange) {
|
||||
RangeVerifier<CXXConstructorDecl> Verifier;
|
||||
Verifier.expectRange(1, 11, 1, 23);
|
||||
EXPECT_TRUE(Verifier.match("class C { C() = default; };", functionDecl()));
|
||||
}
|
||||
|
||||
TEST(CXXConstructorDecl, DeletedCtorLocRange) {
|
||||
RangeVerifier<CXXConstructorDecl> Verifier;
|
||||
Verifier.expectRange(1, 11, 1, 22);
|
||||
EXPECT_TRUE(Verifier.match("class C { C() = delete; };", functionDecl()));
|
||||
}
|
||||
|
||||
TEST(CompoundLiteralExpr, CompoundVectorLiteralRange) {
|
||||
RangeVerifier<CompoundLiteralExpr> Verifier;
|
||||
Verifier.expectRange(2, 11, 2, 22);
|
||||
|
|
Loading…
Reference in New Issue