[clang-tools-extra] [clangd] DefineInline: only trigger on the declaration that has the body (PR #227534)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 30 00:55:10 PDT 2026
================
@@ -400,7 +400,7 @@ class DefineInline : public Tweak {
if (!SelNode)
return false;
Source = getSelectedFunction(SelNode);
- if (!Source || !Source->hasBody())
+ if (!Source || !Source->doesThisDeclarationHaveABody())
----------------
Mrgoudan wrote:
I don't think a late-parsed `Source` is possible here.
The flag is only set by the parser under `LangOpts.DelayedTemplateParsing` ([Parser.cpp#L1252](https://github.com/llvm/llvm-project/blob/58b102609a9d08fbadb9c3fa1dd88bba2cf7f711/clang/lib/Parse/Parser.cpp#L1252),[ParseCXXInlineMethods.cpp#L144](https://github.com/llvm/llvm-project/blob/58b102609a9d08fbadb9c3fa1dd88bba2cf7f711/clang/lib/Parse/ParseCXXInlineMethods.cpp#L144)), and clangd forces that option off for the main file `CI->getLangOpts().DelayedTemplateParsing = false; `([ParsedAST.cpp#L463](https://github.com/llvm/llvm-project/blob/58b102609a9d08fbadb9c3fa1dd88bba2cf7f711/clang-tools-extra/clangd/ParsedAST.cpp#L463))`
`Source` is the selected decl, so it is always in the main file; only the preamble can still be late-parsed, and a preamble decl can only be `Target`, whose body we never read.
Also, `hasBody()` wouldn't help with this: it is just `doesThisDeclarationHaveABody()` over the redecl chain ([Decl.cpp#L3186](https://github.com/llvm/llvm-project/blob/58b102609a9d08fbadb9c3fa1dd88bba2cf7f711/clang/lib/AST/Decl.cpp#L3186)), so the original code had the same exposure.
https://github.com/llvm/llvm-project/pull/227534
More information about the cfe-commits
mailing list