diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp --- a/clang-tools-extra/clangd/FindTarget.cpp +++ b/clang-tools-extra/clangd/FindTarget.cpp @@ -331,6 +331,14 @@ break; } } + void VisitGotoStmt(const GotoStmt *Goto) { + if (auto *LabelDecl = Goto->getLabel()) + Outer.add(LabelDecl, Flags); + } + void VisitLabelStmt(const LabelStmt *Label) { + if (auto *LabelDecl = Label->getDecl()) + Outer.add(LabelDecl, Flags); + } void VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) { const Type *BaseType = E->getBaseType().getTypePtrOrNull(); diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp --- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -130,6 +130,22 @@ } )cpp"; EXPECT_DECLS("CXXOperatorCallExpr", "void operator()(int n)"); + + Code = R"cpp( + void test() { + goto [[label]]; + label: + return; + } + )cpp"; + EXPECT_DECLS("GotoStmt", "label:"); + Code = R"cpp( + void test() { + [[label]]: + return; + } + )cpp"; + EXPECT_DECLS("LabelStmt", "label:"); } TEST_F(TargetDeclTest, Recovery) {