12 #include "clang/AST/Decl.h"
13 #include "clang/AST/DeclTemplate.h"
14 #include "clang/Basic/SourceLocation.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/Support/Casting.h"
17 #include "llvm/Support/raw_ostream.h"
18 #include "llvm/Testing/Support/Annotations.h"
19 #include "gmock/gmock.h"
20 #include "gtest/gtest.h"
21 #include <initializer_list>
35 PrintedDecl(
const char *
Name, DeclRelationSet Relations = {})
36 :
Name(
Name), Relations(Relations) {}
37 PrintedDecl(
const NamedDecl *
D, DeclRelationSet Relations = {})
38 : Relations(Relations) {
40 llvm::raw_string_ostream
OS(S);
42 llvm::StringRef FirstLine =
43 llvm::StringRef(
OS.str()).take_until([](
char C) {
return C ==
'\n'; });
44 FirstLine = FirstLine.rtrim(
" {");
45 Name = std::string(FirstLine.rtrim(
" {"));
49 DeclRelationSet Relations;
51 bool operator==(
const PrintedDecl &L,
const PrintedDecl &R) {
52 return std::tie(L.Name, L.Relations) == std::tie(R.Name, R.Relations);
54 llvm::raw_ostream &
operator<<(llvm::raw_ostream &
OS,
const PrintedDecl &
D) {
55 return OS <<
D.Name <<
" Rel=" <<
D.Relations;
64 class TargetDeclTest :
public ::testing::Test {
73 std::vector<PrintedDecl> assertNodeAndPrintDecls(
const char *NodeType) {
74 llvm::Annotations
A(
Code);
77 auto AST = TU.build();
80 AST.getASTContext(), AST.getTokens(), R.Begin, R.End);
81 const SelectionTree::Node *N = Selection.commonAncestor();
83 ADD_FAILURE() <<
"No node selected!\n" <<
Code;
86 EXPECT_EQ(N->kind(), NodeType) << Selection;
88 std::vector<PrintedDecl> ActualDecls;
89 for (
const auto &
Entry :
91 ActualDecls.emplace_back(
Entry.first,
Entry.second);
98 #define EXPECT_DECLS(NodeType, ...) \
99 EXPECT_THAT(assertNodeAndPrintDecls(NodeType), \
100 ::testing::UnorderedElementsAreArray( \
101 std::vector<PrintedDecl>({__VA_ARGS__}))) \
103 using ExpectedDecls = std::vector<PrintedDecl>;
105 TEST_F(TargetDeclTest, Exprs) {
113 struct S { S operator+(S) const; };
114 auto X = S() [[+]] S();
126 void operator()(int n);
133 EXPECT_DECLS("CXXOperatorCallExpr",
"void operator()(int n)");
152 TEST_F(TargetDeclTest, RecoveryForC) {
153 Flags = {
"-xc",
"-Xclang",
"-frecovery-ast"};
155 // error-ok: testing behavior on broken code
163 TEST_F(TargetDeclTest, Recovery) {
165 // error-ok: testing behavior on broken code
170 EXPECT_DECLS("UnresolvedLookupExpr",
"int f()",
"int f(int, int)");
173 TEST_F(TargetDeclTest, RecoveryType) {
175 // error-ok: testing behavior on broken code
176 struct S { int member; };
179 // No overload matches, but we have recovery-expr with the correct type.
180 overloaded().[[member]];
186 TEST_F(TargetDeclTest, UsingDecl) {
196 EXPECT_DECLS(
"DeclRefExpr", {
"using foo::f", Rel::Alias}, {
"int f(int)"});
206 EXPECT_DECLS(
"UsingDecl", {
"using foo::f", Rel::Alias}, {
"int f(int)"},
216 int x = Y().[[foo]]();
218 EXPECT_DECLS("MemberExpr", {
"using X::foo", Rel::Alias}, {
"int foo()"});
221 template <typename T>
225 template <typename T>
226 struct Derived : Base<T> {
227 using Base<T>::[[waldo]];
230 EXPECT_DECLS("UnresolvedUsingValueDecl", {
"using Base<T>::waldo", Rel::Alias},
235 template<typename T> class S {};
243 EXPECT_DECLS("TemplateSpecializationTypeLoc", {
"using ns::S", Rel::Alias},
244 {
"template <typename T> class S"},
245 {
"class S", Rel::TemplatePattern});
249 template<typename T> class S {};
253 template <template <typename> class T> class X {};
256 EXPECT_DECLS("TemplateArgumentLoc", {
"using ns::S", Rel::Alias},
257 {
"template <typename T> class S"});
261 template<typename T> class S { public: S(T); };
267 Flags.push_back("-std=c++17");
269 {
"using ns::S", Rel::Alias}, {
"template <typename T> class S"},
270 {
"class S", Rel::TemplatePattern});
274 class Foo { public: class foo {}; };
275 template <class T> class A : public Foo<T> {
276 using typename Foo<T>::foo;
281 {
"using typename Foo<T>::foo", Rel::Alias});
284 TEST_F(TargetDeclTest, BaseSpecifier) {
287 struct Y : [[private]] X {};
292 struct Y : [[private X]] {};
297 struct Y : private [[X]] {};
302 TEST_F(TargetDeclTest, ConstructorInitList) {
320 TEST_F(TargetDeclTest, DesignatedInit) {
324 struct Y { int b; struct X c[2]; };
325 struct Y y = { .c[0].[[a]] = 1 };
330 TEST_F(TargetDeclTest, NestedNameSpecifier) {
332 namespace a { namespace b { int c; } }
338 namespace a { struct X { enum { y }; }; }
344 template <typename T>
350 namespace a { int x; }
354 EXPECT_DECLS("NestedNameSpecifierLoc", {
"namespace b = a", Rel::Alias},
355 {
"namespace a", Rel::Underlying});
358 TEST_F(TargetDeclTest, Types) {
370 EXPECT_DECLS("TypedefTypeLoc", {
"typedef S X", Rel::Alias},
371 {
"struct S", Rel::Underlying});
373 namespace ns { struct S{}; }
377 EXPECT_DECLS("TypedefTypeLoc", {
"typedef ns::S X", Rel::Alias},
378 {
"struct S", Rel::Underlying});
382 void foo() { [[T]] x; }
388 template<template<typename> class T>
389 void foo() { [[T<int>]] x; }
391 EXPECT_DECLS("TemplateSpecializationTypeLoc",
"template <typename> class T");
395 template<template<typename> class ...T>
400 EXPECT_DECLS("TemplateArgumentLoc", {
"template <typename> class ...T"});
408 EXPECT_DECLS("DecltypeTypeLoc", {
"struct S", Rel::Underlying});
418 template <typename... E>
420 static const int size = sizeof...([[E]]);
426 template <typename T>
434 TEST_F(TargetDeclTest, ClassTemplate) {
436 // Implicit specialization.
437 template<int x> class Foo{};
441 {
"template<> class Foo<42>", Rel::TemplateInstantiation},
442 {
"class Foo", Rel::TemplatePattern});
445 template<typename T> class Foo {};
446 // The "Foo<int>" SpecializationDecl is incomplete, there is no
447 // instantiation happening.
448 void func([[Foo<int>]] *);
451 {
"class Foo", Rel::TemplatePattern},
452 {
"template<> class Foo<int>", Rel::TemplateInstantiation});
455 // Explicit specialization.
456 template<int x> class Foo{};
457 template<> class Foo<42>{};
460 EXPECT_DECLS("TemplateSpecializationTypeLoc",
"template<> class Foo<42>");
463 // Partial specialization.
464 template<typename T> class Foo{};
465 template<typename T> class Foo<T*>{};
469 {
"template<> class Foo<int *>", Rel::TemplateInstantiation},
470 {
"template <typename T> class Foo<T *>", Rel::TemplatePattern});
473 // Template template argument.
474 template<typename T> struct Vector {};
475 template <template <typename> class Container>
479 EXPECT_DECLS("TemplateArgumentLoc", {
"template <typename T> struct Vector"});
481 Flags.push_back(
"-std=c++17");
484 // Class template argument deduction
485 template <typename T>
494 {
"struct Test", Rel::TemplatePattern});
498 template <typename T>
500 template <typename I>
503 template <typename I>
504 [[Test]](I, I) -> Test<typename I::type>;
506 EXPECT_DECLS("CXXDeductionGuideDecl", {
"template <typename T> struct Test"});
509 TEST_F(TargetDeclTest, Concept) {
510 Flags.push_back(
"-std=c++20");
516 template <typename T>
517 concept Fooable = requires (T t) { t.foo(); };
519 template <typename T> requires [[Fooable]]<T>
525 "ConceptSpecializationExpr",
526 {
"template <typename T> concept Fooable = requires (T t) { t.foo(); }"});
530 template <typename T>
531 concept Fooable = true;
533 template <typename T>
534 void foo() requires [[Fooable]]<T>;
537 {
"template <typename T> concept Fooable = true"});
541 template <typename T>
542 concept Fooable = true;
544 template <[[Fooable]] T>
548 {
"template <typename T> concept Fooable = true"});
552 template <typename T, typename U>
553 concept Fooable = true;
555 template <[[Fooable]]<int> T>
559 {
"template <typename T, typename U> concept Fooable = true"});
562 TEST_F(TargetDeclTest, Coroutine) {
563 Flags.push_back(
"-std=c++20");
566 namespace std::experimental {
567 template <typename, typename...> struct coroutine_traits;
568 template <typename> struct coroutine_handle {
569 template <typename U>
570 coroutine_handle(coroutine_handle<U>&&) noexcept;
571 static coroutine_handle from_address(void* __addr) noexcept;
573 } // namespace std::experimental
577 struct awaitable_frame {
578 awaitable get_return_object();
580 void unhandled_exception();
583 bool await_ready() const noexcept;
584 void await_suspend(std::experimental::coroutine_handle<void>) noexcept;
585 void await_resume() const noexcept;
587 result_t initial_suspend() noexcept;
588 result_t final_suspend() noexcept;
589 result_t await_transform(executor) noexcept;
592 namespace std::experimental {
594 struct coroutine_traits<awaitable> {
595 typedef awaitable_frame promise_type;
597 } // namespace std::experimental
600 co_await [[executor]]();
606 TEST_F(TargetDeclTest, FunctionTemplate) {
608 // Implicit specialization.
609 template<typename T> bool foo(T) { return false; };
610 bool x = [[foo]](42);
613 {
"template<> bool foo<int>(int)", Rel::TemplateInstantiation},
614 {
"bool foo(T)", Rel::TemplatePattern});
617 // Explicit specialization.
618 template<typename T> bool foo(T) { return false; };
619 template<> bool foo<int>(int) { return false; };
620 bool x = [[foo]](42);
622 EXPECT_DECLS("DeclRefExpr",
"template<> bool foo<int>(int)");
625 TEST_F(TargetDeclTest, VariableTemplate) {
628 // Implicit specialization.
629 template<typename T> int foo;
630 int x = [[foo]]<char>;
632 EXPECT_DECLS("DeclRefExpr", {
"int foo", Rel::TemplateInstantiation},
633 {
"int foo", Rel::TemplatePattern});
636 // Explicit specialization.
637 template<typename T> int foo;
638 template <> bool foo<char>;
639 int x = [[foo]]<char>;
644 // Partial specialization.
645 template<typename T> int foo;
646 template<typename T> bool foo<T*>;
647 bool x = [[foo]]<char*>;
649 EXPECT_DECLS("DeclRefExpr", {
"bool foo", Rel::TemplateInstantiation},
650 {
"bool foo", Rel::TemplatePattern});
653 TEST_F(TargetDeclTest, TypeAliasTemplate) {
655 template<typename T, int X> class SmallVector {};
656 template<typename U> using TinyVector = SmallVector<U, 1>;
657 [[TinyVector<int>]] X;
660 {
"template<> class SmallVector<int, 1>",
661 Rel::TemplateInstantiation | Rel::Underlying},
662 {
"class SmallVector", Rel::TemplatePattern | Rel::Underlying},
663 {
"using TinyVector = SmallVector<U, 1>",
664 Rel::Alias | Rel::TemplatePattern});
667 TEST_F(TargetDeclTest, MemberOfTemplate) {
669 template <typename T> struct Foo {
672 int y = Foo<int>().[[x]](42);
674 EXPECT_DECLS("MemberExpr", {
"int x(int)", Rel::TemplateInstantiation},
675 {
"int x(T)", Rel::TemplatePattern});
678 template <typename T> struct Foo {
679 template <typename U>
682 int y = Foo<char>().[[x]]('c', 42);
685 {
"template<> int x<int>(char, int)", Rel::TemplateInstantiation},
686 {
"int x(T, U)", Rel::TemplatePattern});
689 TEST_F(TargetDeclTest, Lambda) {
691 void foo(int x = 42) {
692 auto l = [ [[x]] ]{ return x + 1; };
700 void foo(int x = 42) {
701 auto l = [x]{ return [[x]] + 1; };
708 auto l = [x = 1]{ return [[x]] + 1; };
715 TEST_F(TargetDeclTest, OverloadExpr) {
716 Flags.push_back(
"--target=x86_64-pc-linux-gnu");
727 EXPECT_DECLS("UnresolvedLookupExpr",
"void func(int *)",
"void func(char *)");
740 EXPECT_DECLS("UnresolvedMemberExpr",
"void func(int *)",
"void func(char *)");
744 static void *operator new(unsigned long);
746 auto* k = [[new]] X();
748 EXPECT_DECLS("CXXNewExpr",
"static void *operator new(unsigned long)");
750 void *operator new(unsigned long);
751 auto* k = [[new]] int();
753 EXPECT_DECLS("CXXNewExpr",
"void *operator new(unsigned long)");
757 static void operator delete(void *) noexcept;
763 EXPECT_DECLS("CXXDeleteExpr",
"static void operator delete(void *) noexcept");
765 void operator delete(void *) noexcept;
770 EXPECT_DECLS("CXXDeleteExpr",
"void operator delete(void *) noexcept");
773 TEST_F(TargetDeclTest, DependentExprs) {
776 struct A { void foo() {} };
777 template <typename T>
785 EXPECT_DECLS("CXXDependentScopeMemberExpr",
"void foo()");
795 template <typename T>
799 this->c.getA().[[foo]]();
803 EXPECT_DECLS("CXXDependentScopeMemberExpr",
"void foo()");
814 template <typename T>
818 this->c.fptr().[[foo]]();
822 EXPECT_DECLS("CXXDependentScopeMemberExpr",
"void foo()");
829 template <typename T> struct Foo {
836 EXPECT_DECLS("CXXDependentScopeMemberExpr",
"int aaaa");
842 template <typename T> T convert() const;
844 template <typename T>
846 Foo::k(T()).template [[convert]]<T>();
850 "template <typename T> T convert() const");
853 TEST_F(TargetDeclTest, DependentTypes) {
857 struct A { struct B {}; };
859 template <typename T>
860 void foo(typename A<T>::[[B]]);
867 struct A { struct B { struct C {}; }; };
869 template <typename T>
870 void foo(typename A<T>::[[B]]::C);
878 struct A { struct B { struct C {}; }; };
880 template <typename T>
881 void foo(typename A<T>::B::[[C]]);
889 template <typename> struct B {};
892 template <typename T>
893 void foo(typename A<T>::template [[B]]<int>);
896 "template <typename> struct B");
899 TEST_F(TargetDeclTest, TypedefCascade) {
905 using type = C::type;
908 using type = B::type;
913 {
"using type = int", Rel::Alias | Rel::Underlying},
914 {
"using type = C::type", Rel::Alias | Rel::Underlying},
915 {
"using type = B::type", Rel::Alias});
918 TEST_F(TargetDeclTest, RecursiveTemplate) {
919 Flags.push_back(
"-std=c++20");
922 template <typename T>
923 concept Leaf = false;
925 template <typename Tree>
926 struct descend_left {
927 using type = typename descend_left<typename Tree::left>::[[type]];
931 struct descend_left<Tree> {
932 using type = typename Tree::value;
936 {
"using type = typename descend_left<typename Tree::left>::type",
937 Rel::Alias | Rel::Underlying});
940 TEST_F(TargetDeclTest, ObjC) {
941 Flags = {
"-xobjective-c"};
953 @interface Foo { @public int bar; }
970 EXPECT_DECLS("ObjCPropertyRefExpr",
"- (void)setX:(int)x");
974 @property(retain) I* x;
975 @property(retain) I* y;
982 "@property(atomic, retain, readwrite) I *x");
988 @property(retain) [[MYObject]] *x;
991 EXPECT_DECLS("ObjCInterfaceTypeLoc",
"@interface MYObject");
997 @property(retain, nonnull) [[MYObject2]] *x;
1000 EXPECT_DECLS("ObjCInterfaceTypeLoc",
"@interface MYObject2");
1006 return [[@protocol(Foo)]];
1014 void test([[Foo]] *p);
1016 EXPECT_DECLS("ObjCInterfaceTypeLoc",
"@interface Foo");
1018 Code = R
"cpp(// Don't consider implicit interface as the target.
1019 @implementation [[Implicit]]
1022 EXPECT_DECLS("ObjCImplementationDecl",
"@implementation Implicit");
1027 @implementation [[Foo]]
1030 EXPECT_DECLS("ObjCImplementationDecl",
"@interface Foo");
1035 @interface Foo (Ext)
1037 @implementation [[Foo]] (Ext)
1040 EXPECT_DECLS("ObjCCategoryImplDecl",
"@interface Foo(Ext)");
1043 void test(id</*error-ok*/[[InvalidProtocol]]> p);
1051 void test([[C]]<Foo> *p);
1059 void test(C<[[Foo]]> *p);
1069 void test(C<[[Foo]], Bar> *p);
1079 void test(C<Foo, [[Bar]]> *p);
1085 + (id)sharedInstance;
1088 + (id)sharedInstance { return 0; }
1091 id value = [[Foo]].sharedInstance;
1094 EXPECT_DECLS("ObjCInterfaceTypeLoc",
"@interface Foo");
1098 + (id)sharedInstance;
1101 + (id)sharedInstance { return 0; }
1104 id value = Foo.[[sharedInstance]];
1107 EXPECT_DECLS("ObjCPropertyRefExpr",
"+ (id)sharedInstance");
1111 + ([[id]])sharedInstance;
1118 + ([[instancetype]])sharedInstance;
1124 class FindExplicitReferencesTest :
public ::testing::Test {
1134 AllRefs annotateReferencesInFoo(llvm::StringRef
Code) {
1136 TU.Code = std::string(
Code);
1140 TU.ExtraArgs.push_back(
"-std=c++20");
1141 TU.ExtraArgs.push_back(
"-xobjective-c++");
1143 auto AST = TU.build();
1144 auto *TestDecl = &
findDecl(AST,
"foo");
1145 if (
auto *T = llvm::dyn_cast<FunctionTemplateDecl>(TestDecl))
1146 TestDecl = T->getTemplatedDecl();
1148 std::vector<ReferenceLoc>
Refs;
1149 if (
const auto *Func = llvm::dyn_cast<FunctionDecl>(TestDecl))
1152 [&
Refs](ReferenceLoc R) { Refs.push_back(std::move(R)); },
1153 AST.getHeuristicResolver());
1154 else if (
const auto *NS = llvm::dyn_cast<NamespaceDecl>(TestDecl))
1157 [&
Refs, &NS](ReferenceLoc R) {
1159 if (R.Targets.size() == 1 && R.Targets.front() == NS)
1161 Refs.push_back(std::move(R));
1163 AST.getHeuristicResolver());
1165 ADD_FAILURE() <<
"Failed to find ::foo decl for test";
1167 auto &SM = AST.getSourceManager();
1168 llvm::sort(
Refs, [&](
const ReferenceLoc &L,
const ReferenceLoc &R) {
1169 return SM.isBeforeInTranslationUnit(L.NameLoc, R.NameLoc);
1173 unsigned NextCodeChar = 0;
1174 for (
unsigned I = 0; I <
Refs.size(); ++I) {
1177 SourceLocation
Pos = R.NameLoc;
1178 assert(
Pos.isValid());
1179 if (
Pos.isMacroID())
1180 Pos = SM.getExpansionLoc(
Pos);
1181 assert(
Pos.isFileID());
1185 std::tie(File,
Offset) = SM.getDecomposedLoc(
Pos);
1186 if (File == SM.getMainFileID()) {
1188 assert(NextCodeChar <=
Offset);
1198 for (
unsigned I = 0; I <
Refs.size(); ++I)
1205 TEST_F(FindExplicitReferencesTest, All) {
1206 std::pair< llvm::StringRef, llvm::StringRef> Cases[] =
1211 void foo(int param) {
1212 $0^global = $1^param + $2^func();
1215 "0: targets = {global}\n"
1216 "1: targets = {param}\n"
1217 "2: targets = {func}\n"},
1219 struct X { int a; };
1224 "0: targets = {x}\n"
1225 "1: targets = {X::a}\n"},
1227 // error-ok: testing with broken code
1230 return $0^bar() + $1^bar(42);
1233 "0: targets = {bar}\n"
1234 "1: targets = {bar}\n"},
1238 namespace alias = ns;
1240 using namespace $0^ns;
1241 using namespace $1^alias;
1244 "0: targets = {ns}\n"
1245 "1: targets = {alias}\n"},
1248 namespace ns { int global; }
1250 using $0^ns::$1^global;
1253 "0: targets = {ns}\n"
1254 "1: targets = {ns::global}, qualifier = 'ns::'\n"},
1257 struct Struct { int a; };
1258 using Typedef = int;
1262 static_cast<$4^Struct*>(0);
1265 "0: targets = {Struct}\n"
1266 "1: targets = {x}, decl\n"
1267 "2: targets = {Typedef}\n"
1268 "3: targets = {y}, decl\n"
1269 "4: targets = {Struct}\n"},
1272 namespace a { namespace b { struct S { typedef int type; }; } }
1274 $0^a::$1^b::$2^S $3^x;
1275 using namespace $4^a::$5^b;
1279 "0: targets = {a}\n"
1280 "1: targets = {a::b}, qualifier = 'a::'\n"
1281 "2: targets = {a::b::S}, qualifier = 'a::b::'\n"
1282 "3: targets = {x}, decl\n"
1283 "4: targets = {a}\n"
1284 "5: targets = {a::b}, qualifier = 'a::'\n"
1285 "6: targets = {a::b::S}\n"
1286 "7: targets = {a::b::S::type}, qualifier = 'struct S::'\n"
1287 "8: targets = {y}, decl\n"},
1290 $0^ten: // PRINT "HELLO WORLD!"
1294 "0: targets = {ten}, decl\n"
1295 "1: targets = {ten}\n"},
1298 template <class T> struct vector { using value_type = T; };
1299 template <> struct vector<bool> { using value_type = bool; };
1301 $0^vector<int> $1^vi;
1302 $2^vector<bool> $3^vb;
1305 "0: targets = {vector<int>}\n"
1306 "1: targets = {vi}, decl\n"
1307 "2: targets = {vector<bool>}\n"
1308 "3: targets = {vb}, decl\n"},
1311 template <class T> struct vector { using value_type = T; };
1312 template <> struct vector<bool> { using value_type = bool; };
1313 template <class T> using valias = vector<T>;
1315 $0^valias<int> $1^vi;
1316 $2^valias<bool> $3^vb;
1319 "0: targets = {valias}\n"
1320 "1: targets = {vi}, decl\n"
1321 "2: targets = {valias}\n"
1322 "3: targets = {vb}, decl\n"},
1326 template <typename $0^T>
1333 "0: targets = {foo::Bar::T}, decl\n"
1334 "1: targets = {foo::Bar}, decl\n"
1335 "2: targets = {foo::Bar}\n"
1336 "3: targets = {foo::Bar::f}, decl\n"
1337 "4: targets = {foo::Bar}\n"},
1340 struct X { void func(int); };
1348 "0: targets = {y}\n"
1349 "1: targets = {Y::func}\n"},
1352 namespace ns { void bar(int); }
1359 "0: targets = {bar}\n"},
1365 void foo(int a, int b) {
1369 "0: targets = {a}\n"
1370 "1: targets = {b}\n"},
1379 for (int $0^x : $1^vector()) {
1384 "0: targets = {x}, decl\n"
1385 "1: targets = {vector}\n"
1386 "2: targets = {x}\n"},
1389 namespace ns1 { void func(char*); }
1390 namespace ns2 { void func(int*); }
1391 using namespace ns1;
1392 using namespace ns2;
1399 "0: targets = {ns1::func, ns2::func}\n"
1400 "1: targets = {t}\n"},
1409 void foo(X x, T t) {
1413 "0: targets = {x}\n"
1414 "1: targets = {X::func, X::func}\n"
1415 "2: targets = {t}\n"},
1425 $0^S<$1^T>::$2^value;
1428 "0: targets = {S}\n"
1429 "1: targets = {T}\n"
1430 "2: targets = {S::value}, qualifier = 'S<T>::'\n"},
1443 "0: targets = {t}\n"
1444 "1: targets = {S::value}\n"},
1449 static_cast<$0^T>(0);
1454 "0: targets = {T}\n"
1455 "1: targets = {T}\n"
1456 "2: targets = {T}\n"
1457 "3: targets = {t}, decl\n"},
1465 "0: targets = {x}, decl\n"
1466 "1: targets = {I}\n"},
1469 template <class T> struct vector {};
1471 template <template<class> class TT, template<class> class ...TP>
1475 $4^foo<$5^vector>();
1479 "0: targets = {TT}\n"
1480 "1: targets = {x}, decl\n"
1481 "2: targets = {foo}\n"
1482 "3: targets = {TT}\n"
1483 "4: targets = {foo}\n"
1484 "5: targets = {vector}\n"
1485 "6: targets = {foo}\n"
1486 "7: targets = {TP}\n"},
1490 template <int(*)()> struct wrapper {};
1492 template <int(*FuncParam)()>
1494 $0^wrapper<$1^func> $2^w;
1498 "0: targets = {wrapper<&func>}\n"
1499 "1: targets = {func}\n"
1500 "2: targets = {w}, decl\n"
1501 "3: targets = {FuncParam}\n"},
1507 class $0^Foo { $1^Foo(); ~$2^Foo(); int $3^field; };
1509 enum $5^E { $6^ABC };
1511 using $8^INT2 = int;
1512 namespace $9^NS = $10^ns;
1515 "0: targets = {Foo}, decl\n"
1516 "1: targets = {foo()::Foo::Foo}, decl\n"
1517 "2: targets = {Foo}\n"
1518 "3: targets = {foo()::Foo::field}, decl\n"
1519 "4: targets = {Var}, decl\n"
1520 "5: targets = {E}, decl\n"
1521 "6: targets = {foo()::ABC}, decl\n"
1522 "7: targets = {INT}, decl\n"
1523 "8: targets = {INT2}, decl\n"
1524 "9: targets = {NS}, decl\n"
1525 "10: targets = {ns}\n"},
1532 // FIXME: This should have only one reference to Bar.
1533 $2^operator $3^$4^Bar();
1537 $7^f.$8^operator $9^Bar();
1540 "0: targets = {Bar}, decl\n"
1541 "1: targets = {Foo}, decl\n"
1542 "2: targets = {foo()::Foo::operator Bar}, decl\n"
1543 "3: targets = {Bar}\n"
1544 "4: targets = {Bar}\n"
1545 "5: targets = {Foo}\n"
1546 "6: targets = {f}, decl\n"
1547 "7: targets = {f}\n"
1548 "8: targets = {foo()::Foo::operator Bar}\n"
1549 "9: targets = {Bar}\n"},
1557 void $2^destructMe() {
1563 $6^f.~ /*...*/ $7^Foo();
1566 "0: targets = {Foo}, decl\n"
1569 "1: targets = {Foo}\n"
1570 "2: targets = {foo()::Foo::destructMe}, decl\n"
1571 "3: targets = {Foo}\n"
1572 "4: targets = {Foo}\n"
1573 "5: targets = {f}, decl\n"
1574 "6: targets = {f}\n"
1575 "7: targets = {Foo}\n"},
1580 // member initializer
1586 class $4^Derived : public $5^Base {
1588 $8^Derived() : $9^Base() {}
1590 // delegating initializer
1593 $12^Foo(): $13^Foo(111) {}
1597 "0: targets = {X}, decl\n"
1598 "1: targets = {foo()::X::abc}, decl\n"
1599 "2: targets = {foo()::X::X}, decl\n"
1600 "3: targets = {foo()::X::abc}\n"
1601 "4: targets = {Derived}, decl\n"
1602 "5: targets = {Base}\n"
1603 "6: targets = {Base}\n"
1604 "7: targets = {foo()::Derived::B}, decl\n"
1605 "8: targets = {foo()::Derived::Derived}, decl\n"
1606 "9: targets = {Base}\n"
1607 "10: targets = {Foo}, decl\n"
1608 "11: targets = {foo()::Foo::Foo}, decl\n"
1609 "12: targets = {foo()::Foo::Foo}, decl\n"
1610 "13: targets = {Foo}\n"},
1616 int (*$1^fptr)(int $2^a, int) = nullptr;
1619 "0: targets = {x}, decl\n"
1620 "1: targets = {fptr}, decl\n"
1621 "2: targets = {a}, decl\n"},
1625 namespace ns { struct Type {}; }
1626 namespace alias = ns;
1627 namespace rec_alias = alias;
1630 $0^ns::$1^Type $2^a;
1631 $3^alias::$4^Type $5^b;
1632 $6^rec_alias::$7^Type $8^c;
1635 "0: targets = {ns}\n"
1636 "1: targets = {ns::Type}, qualifier = 'ns::'\n"
1637 "2: targets = {a}, decl\n"
1638 "3: targets = {alias}\n"
1639 "4: targets = {ns::Type}, qualifier = 'alias::'\n"
1640 "5: targets = {b}, decl\n"
1641 "6: targets = {rec_alias}\n"
1642 "7: targets = {ns::Type}, qualifier = 'rec_alias::'\n"
1643 "8: targets = {c}, decl\n"},
1647 template <typename... E>
1649 constexpr int $0^size = sizeof...($1^E);
1652 "0: targets = {size}, decl\n"
1653 "1: targets = {E}\n"},
1657 template <typename T>
1665 "0: targets = {Test}\n"
1666 "1: targets = {a}, decl\n"},
1670 template <typename $0^T>
1674 "0: targets = {foo::Bar::T}, decl\n"
1675 "1: targets = {foo::Bar}, decl\n"},
1679 template <typename $0^T>
1683 "0: targets = {T}, decl\n"
1684 "1: targets = {foo::func}, decl\n"},
1688 template <typename $0^T>
1692 "0: targets = {foo::T}, decl\n"
1693 "1: targets = {foo::T}\n"
1694 "2: targets = {foo::x}, decl\n"},
1697 template<typename T> class vector {};
1699 template <typename $0^T>
1700 using $1^V = $2^vector<$3^T>;
1703 "0: targets = {foo::T}, decl\n"
1704 "1: targets = {foo::V}, decl\n"
1705 "2: targets = {vector}\n"
1706 "3: targets = {foo::T}\n"},
1710 template <typename T>
1711 concept Drawable = requires (T t) { t.draw(); };
1714 template <typename $0^T> requires $1^Drawable<$2^T>
1715 void $3^bar($4^T $5^t) {
1720 "0: targets = {T}, decl\n"
1721 "1: targets = {Drawable}\n"
1722 "2: targets = {T}\n"
1723 "3: targets = {foo::bar}, decl\n"
1724 "4: targets = {T}\n"
1725 "5: targets = {t}, decl\n"
1726 "6: targets = {t}\n"
1727 "7: targets = {}\n"},
1741 "0: targets = {f}\n"
1742 "1: targets = {I::_z}\n"},
1747 @property(retain) I* x;
1748 @property(retain) I* y;
1755 "0: targets = {f}\n"
1756 "1: targets = {I::x}\n"
1757 "2: targets = {I::y}\n"},
1770 "0: targets = {f}\n"
1771 "1: targets = {I::x}\n"
1772 "2: targets = {I::setY:}\n"},
1777 @property(class) I *x;
1782 $2^local = $3^I.$4^x;
1785 "0: targets = {I}\n"
1786 "1: targets = {I::setX:}\n"
1787 "2: targets = {local}\n"
1788 "3: targets = {I}\n"
1789 "4: targets = {I::x}\n"},
1800 $2^local = $3^I.$4^x;
1803 "0: targets = {I}\n"
1804 "1: targets = {I::setX:}\n"
1805 "2: targets = {local}\n"
1806 "3: targets = {I}\n"
1807 "4: targets = {I::x}\n"},
1811 -(void) a:(int)x b:(int)y;
1817 "0: targets = {i}\n"
1818 "1: targets = {I::a:b:}\n"},
1829 "0: targets = {I}\n"
1830 "1: targets = {P}\n"
1831 "2: targets = {x}, decl\n"},
1839 $2^Foo $3^f { .$4^Bar = 42 };
1842 "0: targets = {Foo}, decl\n"
1843 "1: targets = {foo()::Foo::Bar}, decl\n"
1844 "2: targets = {Foo}\n"
1845 "3: targets = {f}, decl\n"
1846 "4: targets = {foo()::Foo::Bar}\n"},
1855 $5^Bar $6^bar { .$7^Foo.$8^Field = 42 };
1858 "0: targets = {Baz}, decl\n"
1859 "1: targets = {foo()::Baz::Field}, decl\n"
1860 "2: targets = {Bar}, decl\n"
1861 "3: targets = {Baz}\n"
1862 "4: targets = {foo()::Bar::Foo}, decl\n"
1863 "5: targets = {Bar}\n"
1864 "6: targets = {bar}, decl\n"
1865 "7: targets = {foo()::Bar::Foo}\n"
1866 "8: targets = {foo()::Baz::Field}\n"},
1868 template<typename T>
1870 template<typename T>
1872 $0^crash({.$1^x = $2^T()});
1875 "0: targets = {crash}\n"
1877 "2: targets = {T}\n"},
1880 template <template <typename> typename T>
1883 template <typename $0^T>
1884 struct $1^Derive : $2^Base<$3^T::template $4^Unknown> {};
1887 "0: targets = {foo::Derive::T}, decl\n"
1888 "1: targets = {foo::Derive}, decl\n"
1889 "2: targets = {Base}\n"
1890 "3: targets = {foo::Derive::T}\n"
1891 "4: targets = {}, qualifier = 'T::'\n"},
1895 template <typename $0^T>
1897 template <typename $2^I>
1900 template <typename $5^I>
1901 $6^Test($7^I) -> $8^Test<typename $9^I::$10^type>;
1904 "0: targets = {T}, decl\n"
1905 "1: targets = {foo::Test}, decl\n"
1906 "2: targets = {I}, decl\n"
1907 "3: targets = {foo::Test::Test<T>}, decl\n"
1908 "4: targets = {I}\n"
1909 "5: targets = {I}, decl\n"
1910 "6: targets = {foo::Test}\n"
1911 "7: targets = {I}\n"
1912 "8: targets = {foo::Test}\n"
1913 "9: targets = {I}\n"
1914 "10: targets = {}, qualifier = 'I::'\n"}};
1916 for (
const auto &
C : Cases) {
1917 llvm::StringRef ExpectedCode =
C.first;
1918 llvm::StringRef ExpectedRefs =
C.second;
1921 annotateReferencesInFoo(llvm::Annotations(ExpectedCode).code());
1922 EXPECT_EQ(ExpectedCode, Actual.AnnotatedCode);
1923 EXPECT_EQ(ExpectedRefs, Actual.DumpedReferences) << ExpectedCode;