[PATCH] D153331: [clangd][c++20]Consider rewritten binary operators in TargetFinder
Jens Massberg via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 20 05:01:36 PDT 2023
massberg updated this revision to Diff 532867.
massberg added a comment.
Fix test name
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D153331/new/
https://reviews.llvm.org/D153331
Files:
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -4048,6 +4048,38 @@
EXPECT_TRUE(H->Type);
}
+TEST(Hover, RewrittenBinaryOperatorSpaceship) {
+ Annotations T(R"cpp(
+ namespace std {
+ struct strong_ordering {
+ int n;
+ constexpr operator int() const { return n; }
+ static const strong_ordering equal, greater, less;
+ };
+ constexpr strong_ordering strong_ordering::equal = {0};
+ constexpr strong_ordering strong_ordering::greater = {1};
+ constexpr strong_ordering strong_ordering::less = {-1};
+ }
+
+ struct Foo
+ {
+ int x;
+ // Foo spaceship
+ auto operator<=>(const Foo&) const = default;
+ };
+
+ static_assert(Foo(1) !^= Foo(2));
+ )cpp");
+
+ TestTU TU = TestTU::withCode(T.code());
+ TU.ExtraArgs.push_back("-std=c++20");
+ auto AST = TU.build();
+ auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+ EXPECT_EQ(HI->Type,
+ HoverInfo::PrintedType("bool (const Foo &) const noexcept"));
+ EXPECT_EQ(HI->Documentation, "Foo spaceship");
+}
+
} // namespace
} // namespace clangd
} // namespace clang
Index: clang-tools-extra/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -347,6 +347,10 @@
void VisitCXXDeleteExpr(const CXXDeleteExpr *CDE) {
Outer.add(CDE->getOperatorDelete(), Flags);
}
+ void
+ VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *RBO) {
+ Outer.add(RBO->getDecomposedForm().InnerBinOp, Flags);
+ }
};
Visitor(*this, Flags).Visit(S);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153331.532867.patch
Type: text/x-patch
Size: 1834 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230620/eaf48fe1/attachment.bin>
More information about the cfe-commits
mailing list