[PATCH] Fix/Improve SourceRange of defaulted destructors

Daniel Jasper djasper at google.com
Tue Jun 17 04:56:36 PDT 2014


Hi rsmith,

When adding the implicit compound statement (required for Codegen?), the end location was previously overridden by the start location, probably based on the assumptions:
- The location of the implicit compound statement should be the destructor's location
- The compound statement if present is always the last element of a FunctionDecl

This patch changes the location of the compound statement to the destructor's end location, but I am open to other suggestions.

http://reviews.llvm.org/D4175

Files:
  lib/Sema/SemaDeclCXX.cpp
  test/Misc/ast-dump-decl.cpp

Index: lib/Sema/SemaDeclCXX.cpp
===================================================================
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -8880,7 +8880,7 @@
     return;
   }
 
-  SourceLocation Loc = Destructor->getLocation();
+  SourceLocation Loc = Destructor->getLocEnd();
   Destructor->setBody(new (Context) CompoundStmt(Loc));
   Destructor->markUsed(Context);
   MarkVTableUsed(CurrentLocation, ClassDecl);
Index: test/Misc/ast-dump-decl.cpp
===================================================================
--- test/Misc/ast-dump-decl.cpp
+++ test/Misc/ast-dump-decl.cpp
@@ -133,6 +133,18 @@
 // CHECK:      CXXDestructorDecl{{.*}} ~TestCXXDestructorDecl 'void (void) noexcept'
 // CHECK-NEXT:   CompoundStmt
 
+// Test that the range of a defaulted destructor is computed correctly.
+// FIXME: This should include the "= default".
+class Base {
+public:
+  virtual ~Base() {}
+};
+class TestDerived : public Base {
+  TestDerived() {}
+  ~TestDerived() = default;
+};
+// CHECK:      CXXDestructorDecl{{.*}} <line:{{.*}}:3, col:16>
+
 class TestCXXConversionDecl {
   operator int() { return 0; }
 };
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4175.10493.patch
Type: text/x-patch
Size: 1136 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140617/6c7bcd82/attachment.bin>


More information about the cfe-commits mailing list