Author: eliben Date: Mon Mar 23 16:43:28 2015 New Revision: 233028 URL: http://llvm.org/viewvc/llvm-project?rev=233028&view=rev Log: 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 Modified: cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp cfe/trunk/test/Analysis/inlining/path-notes.cpp cfe/trunk/test/Misc/ast-dump-decl.cpp cfe/trunk/unittests/AST/SourceLocationTest.cpp Modified: cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp?rev=233028&r1=233027&r2=233028&view=diff ============================================================================== --- cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp (original) +++ cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp Mon Mar 23 16:43:28 2015 @@ -71,17 +71,24 @@ NamedDecl *Parser::ParseCXXInlineMethodD 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'"); } Modified: cfe/trunk/test/Analysis/inlining/path-notes.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/path-notes.cpp?rev=233028&r1=233027&r2=233028&view=diff ============================================================================== --- cfe/trunk/test/Analysis/inlining/path-notes.cpp (original) +++ cfe/trunk/test/Analysis/inlining/path-notes.cpp Mon Mar 23 16:43:28 2015 @@ -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> Modified: cfe/trunk/test/Misc/ast-dump-decl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/ast-dump-decl.cpp?rev=233028&r1=233027&r2=233028&view=diff ============================================================================== --- cfe/trunk/test/Misc/ast-dump-decl.cpp (original) +++ cfe/trunk/test/Misc/ast-dump-decl.cpp Mon Mar 23 16:43:28 2015 @@ -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; } Modified: cfe/trunk/unittests/AST/SourceLocationTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/SourceLocationTest.cpp?rev=233028&r1=233027&r2=233028&view=diff ============================================================================== --- cfe/trunk/unittests/AST/SourceLocationTest.cpp (original) +++ cfe/trunk/unittests/AST/SourceLocationTest.cpp Mon Mar 23 16:43:28 2015 @@ -122,6 +122,18 @@ TEST(CXXConstructorDecl, NoRetFunTypeLoc 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); _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
