[Clang][Sema] Don't set instantiated from function when rewriting operator<=> (#91339)
The following snippet causes a crash:
```
template<typename T>
struct A
{
bool operator<=>(const A&) const requires true = default;
};
bool f(A<int> a)
{
return a != A<int>();
}
```
This occurs because during the rewrite from `operator<=>` to
`operator==`, the "pattern" `operator<=>` function is set as the
instantiated from function for the newly created `operator==` function.
This is obviously incorrect, and this patch fixes it.
GitOrigin-RevId: d4cf20ca37160cb062a9db773d0e6255d6bbc31a
diff --git a/clangd/unittests/FindTargetTests.cpp b/clangd/unittests/FindTargetTests.cpp
index 9443785..0b2273f 100644
--- a/clangd/unittests/FindTargetTests.cpp
+++ b/clangd/unittests/FindTargetTests.cpp
@@ -642,10 +642,7 @@
bool x = (Foo(1) [[!=]] Foo(2));
)cpp";
EXPECT_DECLS("CXXRewrittenBinaryOperator",
- {"std::strong_ordering operator<=>(const Foo &) const = default",
- Rel::TemplatePattern},
- {"bool operator==(const Foo &) const noexcept = default",
- Rel::TemplateInstantiation});
+ {"bool operator==(const Foo &) const noexcept = default"});
}
TEST_F(TargetDeclTest, FunctionTemplate) {
diff --git a/clangd/unittests/HoverTests.cpp b/clangd/unittests/HoverTests.cpp
index 28df24f..d9e97e5 100644
--- a/clangd/unittests/HoverTests.cpp
+++ b/clangd/unittests/HoverTests.cpp
@@ -3091,7 +3091,7 @@
HI.NamespaceScope = "";
HI.Definition =
"bool operator==(const Foo &) const noexcept = default";
- HI.Documentation = "Foo spaceship";
+ HI.Documentation = "";
}},
};
@@ -3894,7 +3894,7 @@
TU.ExtraArgs.push_back("-std=c++20");
auto AST = TU.build();
auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
- EXPECT_EQ(HI->Documentation, "Foo bar baz");
+ EXPECT_EQ(HI->Documentation, "");
}
TEST(Hover, ForwardStructNoCrash) {