================
@@ -2713,6 +2714,91 @@ TEST(FindReferences, NoQueryForLocalSymbols) {
}
}
+TEST(FindReferences, ForwardingInAST) {
+ Annotations Main(R"cpp(
+ namespace std {
+ template <class T> T &&forward(T &t);
+ template <class T, class... Args> T *make_unique(Args &&...args) {
+ return new T(std::forward<Args>(args)...);
+ }
+ }
+
+ struct Test {
+ $Constructor[[T^est]](){}
+ };
+
+ int main() {
+ auto a = std::$Caller[[make_unique]]<Test>();
+ }
+ )cpp");
+ TestTU TU;
+ TU.Code = std::string(Main.code());
+ auto AST = TU.build();
+
+ EXPECT_THAT(findReferences(AST, Main.point(), 0).References,
+ ElementsAre(rangeIs(Main.range("Constructor")),
+ rangeIs(Main.range("Caller"))));
+}
+
+TEST(FindReferences, ForwardingInASTTwice) {
+ Annotations Main(R"cpp(
+ namespace std {
+ template <class T> T &&forward(T &t);
+ template <class T, class... Args> T *make_unique(Args &&...args) {
+ return new T(forward<Args>(args)...);
+ }
+ template <class T, class... Args> T *make_unique2(Args &&...args) {
+ return make_unique<T>(forward<Args>(args)...);
+ }
+ }
+
+ struct Test {
+ $Constructor[[T^est]](){}
+ };
+
+ int main() {
+ auto a = std::$Caller[[make_unique2]]<Test>();
+ }
+ )cpp");
+ TestTU TU;
+ TU.Code = std::string(Main.code());
+ auto AST = TU.build();
+
+ EXPECT_THAT(findReferences(AST, Main.point(), 0).References,
+ ElementsAre(rangeIs(Main.range("Constructor")),
+ rangeIs(Main.range("Caller"))));
+}
+
+TEST(FindReferences, ForwardingInIndex) {
+ Annotations Header(R"cpp(
+ namespace std {
+ template <class T> T &&forward(T &t);
+ template <class T, class... Args> T *make_unique(Args &&...args) {
+ return new T(std::forward<Args>(args)...);
+ }
+ }
+ struct Test {
+ [[T^est]](){}
+ };
+ )cpp");
+ Annotations Main(R"cpp(
+ #include "header.hpp"
+ int main() {
+ auto a = std::[[make_unique]]<Test>();
+ }
+ )cpp");
+ TestWorkspace TW;
+ TW.addMainFile("header.hpp", Header.code());
+ TW.addMainFile("main.cpp", Main.code());
+ auto AST = TW.openFile("header.hpp").value();
+ auto Index = TW.index();
+
+ EXPECT_THAT(findReferences(AST, Header.point(), 0, Index.get(),
+ /*AddContext*/ true)
+ .References,
+ ElementsAre(rangeIs(Header.range()), rangeIs(Main.range())));
----------------
timon-ul wrote:
I think there is definitely a gap in my understanding of these matchers as of
now so please tell me if my assumption is wrong: `ElementsAre` makes sure that
all of the matchers are correct at least somewhere, this is why just plain in
there the `fileIs` matcher is not that useful there because it would return
true if my matches were in the wrong files as long as a match was in that file?
`AllOf` makes sure that a specific matcher combination is correct.
https://github.com/llvm/llvm-project/pull/169742
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits