[clang] [Clang][AST] Add source range for deleted and defaulted functions (PR #205408)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 15 07:52:15 PDT 2026
================
@@ -111,7 +110,12 @@ NamedDecl *Parser::ParseCXXInlineMethodDef(
Actions.SetDeclDeleted(FnD, KWLoc, Message);
Delete = true;
if (auto *DeclAsFunction = dyn_cast<FunctionDecl>(FnD)) {
- DeclAsFunction->setRangeEnd(KWEndLoc);
+ DeclAsFunction->setRangeEnd(
+ Message ? PrevTokLocation
----------------
AaronBallman wrote:
> @AaronBallman PrevTokLocation points to the start of the last-consumed token,
That is expected -- token ranges go from the start of one token to the start of the final token: https://clang.llvm.org/docs/InternalsManual.html#sourcerange-and-charsourcerange
> PrevTokLocation sits on the d, but the original bug report specifically wants the range to end at the last character of delete (the final e), not the first.
That's not how source ranges work; the end of the range should point to the start of the token for `delete` if there's no message and should point to the `)` if there is a message. In the issue, the problem was that for `void func() = delete;` the end range would point to `)` despite `= delete` being part of the function's definition, so we wanted to expand the range to include the other tokens. But I don't think we want to switch to effectively using char source ranges in the AST.
CC @cor3ntin
https://github.com/llvm/llvm-project/pull/205408
More information about the cfe-commits
mailing list