[clang] [Clang][AST] Add source range for deleted and defaulted functions (PR #205408)
Shreyansh Lodha via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 26 04:56:36 PDT 2026
================
@@ -1308,12 +1308,14 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,
<< 1 /* deleted */;
BodyKind = Sema::FnBodyKind::Delete;
DeletedMessage = ParseCXXDeletedFunctionMessage();
+ D.SetRangeEnd(PP.getLocForEndOfToken(KWLoc).getLocWithOffset(-1));
----------------
lodha1503 wrote:
PP.getLocForEndOfToken(KWLoc) returns a past-the-end location — it points to the character just after the last character of the token (similar to STL's end() iterator). However, Clang source ranges are inclusive, meaning the end location must point to the actual last character of the token, not one past it.
So .getLocWithOffset(-1) moves back one character to land on the last character of delete/default.
My fix follows the same approach for out-of-class definitions.
Commit 5f4d76efd365 from March 23, 2015 by Eli Bendersky, titled "Record correct source range for defaulted/deleted members":
SourceLocation KWEndLoc = Tok.getEndLoc().getLocWithOffset(-1);
(established this pattern for inline members).
This is exactly the same pattern I used. That 2015 fix handled functions inside a class body (ParseCXXInlineMethods.cpp). My fix extends the same logic to functions outside the class body (Parser.cpp) — which is why I followed the same pattern for consistency.
Technically if we removed getLocWithOffset(-1) AND updated the CHECK column numbers by +1 to match, the test would still pass.
https://github.com/llvm/llvm-project/pull/205408
More information about the cfe-commits
mailing list