zyn0217 wrote:

Another issue I've encountered while at it is that, given the following code,
```cpp
void foo();
auto lambda = [] {
  return ^foo();
};
```
let `N` represent the selection node for the expression `foo()`, 
`N.getDeclContext()` then yields `TranslationUnitDecl` rather than the 
`CXXRecordDecl`of the lambda expression.
I presume there's something wrong at `SelectionTree::Node::getDeclContext()`, 
because lambda expressions would slip through the current traversal logic.

```txt
`-LambdaExpr <col:15, line:4:1> '(lambda at line:2:15)'    <-- parent 3; not a 
Decl thus ignored!
  |-CXXRecordDecl <line:2:15> col:15 implicit class definition
  | |-DefinitionData
  | | |-DefaultConstructor
  | | |-CopyConstructor
  | | |-MoveConstructor
  | | |-CopyAssignment
  | | |-MoveAssignment
  | | `-Destructor
  | |-CXXMethodDecl <col:16, line:4:1> line:2:15 constexpr operator() 'auto () 
const -> void' inline
  | | `-CompoundStmt <col:18, line:4:1>
  | |   `-ReturnStmt <line:3:3, col:14>
  | |     `-CallExpr <col:10, col:14> 'void'
  | |       `-ImplicitCastExpr <col:10> 'void (*)()' <FunctionToPointerDecay>
  | |         `-DeclRefExpr <col:10> 'void ()' lvalue Function 0xb76c1c8 'foo' 
'void ()'
  | |-CXXConversionDecl <line:2:15, line:4:1> line:2:15 implicit constexpr 
operator void (*)() 'auto (*() const noexcept)() -> void' inline
  | |-CXXMethodDecl <col:15, line:4:1> line:2:15 implicit __invoke 'auto () -> 
void' static inline
  | `-CXXDestructorDecl <col:15> col:15 implicit referenced constexpr ~(lambda 
at line:2:15) 'void () noexcept' inline default trivial
  `-CompoundStmt <col:18, line:4:1>       <--parent 2
    `-ReturnStmt <line:3:3, col:14>           <-- parent 1
      `-CallExpr <col:10, col:14> 'void'       <-- starting point
        `-ImplicitCastExpr <col:10> 'void (*)()' <FunctionToPointerDecay>
          `-DeclRefExpr <col:10> 'void ()' lvalue Function 0xb76c1c8 'foo' 
'void ()'
```

https://github.com/llvm/llvm-project/blob/51b988efb06f0343e7b71c9aec9ec3195412179d/clang-tools-extra/clangd/Selection.cpp#L1107-L1118

https://github.com/llvm/llvm-project/pull/71279
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to