xref: /llvm-project/clang/unittests/AST/ASTImporterGenericRedeclTest.cpp (revision 9f80ecb308c989523cc32d4256f7ab61c5b788d7)
1 //===- unittest/AST/ASTImporterTest.cpp - AST node import test ------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Type-parameterized tests for the correct import of redecl chains.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "ASTImporterFixtures.h"
14 
15 namespace clang {
16 namespace ast_matchers {
17 
18 using internal::BindableMatcher;
19 
20 struct Function {
21   using DeclTy = FunctionDecl;
22   static constexpr auto *Prototype = "void X();";
23   static constexpr auto *Definition = "void X() {}";
getPatternclang::ast_matchers::Function24   BindableMatcher<Decl> getPattern() {
25     return functionDecl(hasName("X"), unless(isImplicit()));
26   }
27 };
28 
29 struct Class {
30   using DeclTy = CXXRecordDecl;
31   static constexpr auto *Prototype = "class X;";
32   static constexpr auto *Definition = "class X {};";
getPatternclang::ast_matchers::Class33   BindableMatcher<Decl> getPattern() {
34     return cxxRecordDecl(hasName("X"), unless(isImplicit()));
35   }
36 };
37 
38 struct EnumClass {
39   using DeclTy = EnumDecl;
40   static constexpr auto *Prototype = "enum class X;";
41   static constexpr auto *Definition = "enum class X {};";
getPatternclang::ast_matchers::EnumClass42   BindableMatcher<Decl> getPattern() {
43     return enumDecl(hasName("X"), unless(isImplicit()));
44   }
45 };
46 
47 struct Variable {
48   using DeclTy = VarDecl;
49   static constexpr auto *Prototype = "extern int X;";
50   static constexpr auto *Definition = "int X;";
getPatternclang::ast_matchers::Variable51   BindableMatcher<Decl> getPattern() { return varDecl(hasName("X")); }
52 };
53 
54 struct FunctionTemplate {
55   using DeclTy = FunctionTemplateDecl;
56   static constexpr auto *Prototype = "template <class T> void X();";
57   static constexpr auto *Definition =
58       R"(
59       template <class T> void X() {};
60       // Explicit instantiation is a must because of -fdelayed-template-parsing:
61       template void X<int>();
62       )";
getPatternclang::ast_matchers::FunctionTemplate63   BindableMatcher<Decl> getPattern() {
64     return functionTemplateDecl(hasName("X"), unless(isImplicit()));
65   }
66 };
67 
68 struct ClassTemplate {
69   using DeclTy = ClassTemplateDecl;
70   static constexpr auto *Prototype = "template <class T> class X;";
71   static constexpr auto *Definition = "template <class T> class X {};";
getPatternclang::ast_matchers::ClassTemplate72   BindableMatcher<Decl> getPattern() {
73     return classTemplateDecl(hasName("X"), unless(isImplicit()));
74   }
75 };
76 
77 struct VariableTemplate {
78   using DeclTy = VarTemplateDecl;
79   static constexpr auto *Prototype = "template <class T> extern T X;";
80   static constexpr auto *Definition =
81       R"(
82       template <class T> T X;
83       )";
84   // There is no matcher for varTemplateDecl so use a work-around.
getPatternclang::ast_matchers::VariableTemplate85   BindableMatcher<Decl> getPattern() {
86     return namedDecl(hasName("X"), unless(isImplicit()),
87                      has(templateTypeParmDecl()));
88   }
89 };
90 
91 struct FunctionTemplateSpec {
92   using DeclTy = FunctionDecl;
93   static constexpr auto *Prototype =
94       R"(
95       // Proto of the primary template.
96       template <class T>
97       void X();
98       // Proto of the specialization.
99       template <>
100       void X<int>();
101       )";
102   static constexpr auto *Definition =
103       R"(
104       // Proto of the primary template.
105       template <class T>
106       void X();
107       // Specialization and definition.
108       template <>
109       void X<int>() {}
110       )";
getPatternclang::ast_matchers::FunctionTemplateSpec111   BindableMatcher<Decl> getPattern() {
112     return functionDecl(hasName("X"), isExplicitTemplateSpecialization());
113   }
114 };
115 
116 struct ClassTemplateSpec {
117   using DeclTy = ClassTemplateSpecializationDecl;
118   static constexpr auto *Prototype =
119       R"(
120       template <class T> class X;
121       template <> class X<int>;
122       )";
123   static constexpr auto *Definition =
124       R"(
125       template <class T> class X;
126       template <> class X<int> {};
127       )";
getPatternclang::ast_matchers::ClassTemplateSpec128   BindableMatcher<Decl> getPattern() {
129     return classTemplateSpecializationDecl(hasName("X"), unless(isImplicit()));
130   }
131 };
132 
133 const internal::VariadicDynCastAllOfMatcher<Decl, VarTemplateDecl>
134     varTemplateDecl;
135 const internal::VariadicDynCastAllOfMatcher<Decl, VarTemplateSpecializationDecl>
136     varTemplateSpecializationDecl;
137 
138 struct VariableTemplateSpec {
139   using DeclTy = VarTemplateSpecializationDecl;
140   static constexpr auto *Prototype =
141       R"(
142       template <class T> extern T X;
143       template <> extern int X<int>;
144       )";
145   static constexpr auto *Definition =
146       R"(
147       template <class T> T X;
148       template <> int X<int>;
149       )";
getPatternclang::ast_matchers::VariableTemplateSpec150   BindableMatcher<Decl> getPattern() {
151     return varTemplateSpecializationDecl(hasName("X"), unless(isImplicit()));
152   }
153 };
154 
155 template <typename TypeParam>
156 struct RedeclChain : ASTImporterOptionSpecificTestBase {
157 
158   using DeclTy = typename TypeParam::DeclTy;
getPrototypeclang::ast_matchers::RedeclChain159   std::string getPrototype() { return TypeParam::Prototype; }
getDefinitionclang::ast_matchers::RedeclChain160   std::string getDefinition() { return TypeParam::Definition; }
getPatternclang::ast_matchers::RedeclChain161   BindableMatcher<Decl> getPattern() const { return TypeParam().getPattern(); }
162 
CheckPreviousDeclclang::ast_matchers::RedeclChain163   void CheckPreviousDecl(Decl *Prev, Decl *Current) {
164     ASSERT_NE(Prev, Current);
165     ASSERT_EQ(&Prev->getASTContext(), &Current->getASTContext());
166     EXPECT_EQ(Prev->getCanonicalDecl(), Current->getCanonicalDecl());
167 
168     // Templates.
169     if (auto *PrevT = dyn_cast<TemplateDecl>(Prev)) {
170       EXPECT_EQ(Current->getPreviousDecl(), Prev);
171       auto *CurrentT = cast<TemplateDecl>(Current);
172       ASSERT_TRUE(PrevT->getTemplatedDecl());
173       ASSERT_TRUE(CurrentT->getTemplatedDecl());
174       EXPECT_EQ(CurrentT->getTemplatedDecl()->getPreviousDecl(),
175                 PrevT->getTemplatedDecl());
176       return;
177     }
178 
179     // Specializations.
180     if (auto *PrevF = dyn_cast<FunctionDecl>(Prev)) {
181       if (PrevF->getTemplatedKind() ==
182           FunctionDecl::TK_FunctionTemplateSpecialization) {
183         // There may be a hidden fwd spec decl before a spec decl.
184         // In that case the previous visible decl can be reached through that
185         // invisible one.
186         EXPECT_THAT(Prev, testing::AnyOf(
187                               Current->getPreviousDecl(),
188                               Current->getPreviousDecl()->getPreviousDecl()));
189         auto *ToTU = Prev->getTranslationUnitDecl();
190         auto *TemplateD = FirstDeclMatcher<FunctionTemplateDecl>().match(
191             ToTU, functionTemplateDecl());
192         auto *FirstSpecD = *(TemplateD->spec_begin());
193         EXPECT_EQ(FirstSpecD->getCanonicalDecl(), PrevF->getCanonicalDecl());
194         return;
195       }
196     }
197 
198     // The rest: Classes, Functions, etc.
199     EXPECT_EQ(Current->getPreviousDecl(), Prev);
200   }
201 
202   void
TypedTest_PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinitionclang::ast_matchers::RedeclChain203   TypedTest_PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition() {
204     Decl *FromTU = getTuDecl(getPrototype(), Lang_CXX03);
205     auto *FromD = FirstDeclMatcher<DeclTy>().match(FromTU, getPattern());
206     ASSERT_FALSE(FromD->isThisDeclarationADefinition());
207 
208     Decl *ImportedD = Import(FromD, Lang_CXX03);
209     Decl *ToTU = ImportedD->getTranslationUnitDecl();
210 
211     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 1u);
212     auto *ToD = LastDeclMatcher<DeclTy>().match(ToTU, getPattern());
213     EXPECT_TRUE(ImportedD == ToD);
214     EXPECT_FALSE(ToD->isThisDeclarationADefinition());
215     if (auto *ToT = dyn_cast<TemplateDecl>(ToD)) {
216       EXPECT_TRUE(ToT->getTemplatedDecl());
217     }
218   }
219 
TypedTest_DefinitionShouldBeImportedAsADefinitionclang::ast_matchers::RedeclChain220   void TypedTest_DefinitionShouldBeImportedAsADefinition() {
221     Decl *FromTU = getTuDecl(getDefinition(), Lang_CXX03);
222     auto *FromD = FirstDeclMatcher<DeclTy>().match(FromTU, getPattern());
223     ASSERT_TRUE(FromD->isThisDeclarationADefinition());
224 
225     Decl *ImportedD = Import(FromD, Lang_CXX03);
226     Decl *ToTU = ImportedD->getTranslationUnitDecl();
227 
228     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 1u);
229     auto *ToD = LastDeclMatcher<DeclTy>().match(ToTU, getPattern());
230     EXPECT_TRUE(ToD->isThisDeclarationADefinition());
231     if (auto *ToT = dyn_cast<TemplateDecl>(ToD)) {
232       EXPECT_TRUE(ToT->getTemplatedDecl());
233     }
234   }
235 
TypedTest_ImportPrototypeAfterImportedPrototypeclang::ast_matchers::RedeclChain236   void TypedTest_ImportPrototypeAfterImportedPrototype() {
237     Decl *FromTU = getTuDecl(getPrototype() + getPrototype(), Lang_CXX03);
238     auto *From0 = FirstDeclMatcher<DeclTy>().match(FromTU, getPattern());
239     auto *From1 = LastDeclMatcher<DeclTy>().match(FromTU, getPattern());
240     ASSERT_FALSE(From0->isThisDeclarationADefinition());
241     ASSERT_FALSE(From1->isThisDeclarationADefinition());
242 
243     Decl *Imported0 = Import(From0, Lang_CXX03);
244     Decl *Imported1 = Import(From1, Lang_CXX03);
245     Decl *ToTU = Imported0->getTranslationUnitDecl();
246 
247     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 2u);
248     auto *To0 = FirstDeclMatcher<DeclTy>().match(ToTU, getPattern());
249     auto *To1 = LastDeclMatcher<DeclTy>().match(ToTU, getPattern());
250     EXPECT_TRUE(Imported0 == To0);
251     EXPECT_TRUE(Imported1 == To1);
252     EXPECT_FALSE(To0->isThisDeclarationADefinition());
253     EXPECT_FALSE(To1->isThisDeclarationADefinition());
254 
255     CheckPreviousDecl(To0, To1);
256   }
257 
TypedTest_ImportDefinitionAfterImportedPrototypeclang::ast_matchers::RedeclChain258   void TypedTest_ImportDefinitionAfterImportedPrototype() {
259     Decl *FromTU = getTuDecl(getPrototype() + getDefinition(), Lang_CXX03);
260     auto *FromProto = FirstDeclMatcher<DeclTy>().match(FromTU, getPattern());
261     auto *FromDef = LastDeclMatcher<DeclTy>().match(FromTU, getPattern());
262     ASSERT_FALSE(FromProto->isThisDeclarationADefinition());
263     ASSERT_TRUE(FromDef->isThisDeclarationADefinition());
264 
265     Decl *ImportedProto = Import(FromProto, Lang_CXX03);
266     Decl *ImportedDef = Import(FromDef, Lang_CXX03);
267     Decl *ToTU = ImportedProto->getTranslationUnitDecl();
268 
269     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 2u);
270     auto *ToProto = FirstDeclMatcher<DeclTy>().match(ToTU, getPattern());
271     auto *ToDef = LastDeclMatcher<DeclTy>().match(ToTU, getPattern());
272     EXPECT_TRUE(ImportedProto == ToProto);
273     EXPECT_TRUE(ImportedDef == ToDef);
274     EXPECT_FALSE(ToProto->isThisDeclarationADefinition());
275     EXPECT_TRUE(ToDef->isThisDeclarationADefinition());
276 
277     CheckPreviousDecl(ToProto, ToDef);
278   }
279 
TypedTest_ImportPrototypeAfterImportedDefinitionclang::ast_matchers::RedeclChain280   void TypedTest_ImportPrototypeAfterImportedDefinition() {
281     Decl *FromTU = getTuDecl(getDefinition() + getPrototype(), Lang_CXX03);
282     auto *FromDef = FirstDeclMatcher<DeclTy>().match(FromTU, getPattern());
283     auto *FromProto = LastDeclMatcher<DeclTy>().match(FromTU, getPattern());
284     ASSERT_TRUE(FromDef->isThisDeclarationADefinition());
285     ASSERT_FALSE(FromProto->isThisDeclarationADefinition());
286 
287     Decl *ImportedDef = Import(FromDef, Lang_CXX03);
288     Decl *ImportedProto = Import(FromProto, Lang_CXX03);
289     Decl *ToTU = ImportedDef->getTranslationUnitDecl();
290 
291     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 2u);
292     auto *ToDef = FirstDeclMatcher<DeclTy>().match(ToTU, getPattern());
293     auto *ToProto = LastDeclMatcher<DeclTy>().match(ToTU, getPattern());
294     EXPECT_TRUE(ImportedDef == ToDef);
295     EXPECT_TRUE(ImportedProto == ToProto);
296     EXPECT_TRUE(ToDef->isThisDeclarationADefinition());
297     EXPECT_FALSE(ToProto->isThisDeclarationADefinition());
298 
299     CheckPreviousDecl(ToDef, ToProto);
300   }
301 
TypedTest_ImportPrototypesclang::ast_matchers::RedeclChain302   void TypedTest_ImportPrototypes() {
303     Decl *FromTU0 = getTuDecl(getPrototype(), Lang_CXX03, "input0.cc");
304     Decl *FromTU1 = getTuDecl(getPrototype(), Lang_CXX03, "input1.cc");
305     auto *From0 = FirstDeclMatcher<DeclTy>().match(FromTU0, getPattern());
306     auto *From1 = FirstDeclMatcher<DeclTy>().match(FromTU1, getPattern());
307     ASSERT_FALSE(From0->isThisDeclarationADefinition());
308     ASSERT_FALSE(From1->isThisDeclarationADefinition());
309 
310     Decl *Imported0 = Import(From0, Lang_CXX03);
311     Decl *Imported1 = Import(From1, Lang_CXX03);
312     Decl *ToTU = Imported0->getTranslationUnitDecl();
313 
314     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 2u);
315     auto *To0 = FirstDeclMatcher<DeclTy>().match(ToTU, getPattern());
316     auto *To1 = LastDeclMatcher<DeclTy>().match(ToTU, getPattern());
317     EXPECT_TRUE(Imported0 == To0);
318     EXPECT_TRUE(Imported1 == To1);
319     EXPECT_FALSE(To0->isThisDeclarationADefinition());
320     EXPECT_FALSE(To1->isThisDeclarationADefinition());
321 
322     CheckPreviousDecl(To0, To1);
323   }
324 
TypedTest_ImportDefinitionsclang::ast_matchers::RedeclChain325   void TypedTest_ImportDefinitions() {
326     Decl *FromTU0 = getTuDecl(getDefinition(), Lang_CXX03, "input0.cc");
327     Decl *FromTU1 = getTuDecl(getDefinition(), Lang_CXX03, "input1.cc");
328     auto *From0 = FirstDeclMatcher<DeclTy>().match(FromTU0, getPattern());
329     auto *From1 = FirstDeclMatcher<DeclTy>().match(FromTU1, getPattern());
330     ASSERT_TRUE(From0->isThisDeclarationADefinition());
331     ASSERT_TRUE(From1->isThisDeclarationADefinition());
332 
333     Decl *Imported0 = Import(From0, Lang_CXX03);
334     Decl *Imported1 = Import(From1, Lang_CXX03);
335     Decl *ToTU = Imported0->getTranslationUnitDecl();
336 
337     EXPECT_EQ(Imported0, Imported1);
338     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 1u);
339     auto *To0 = FirstDeclMatcher<DeclTy>().match(ToTU, getPattern());
340     EXPECT_TRUE(Imported0 == To0);
341     EXPECT_TRUE(To0->isThisDeclarationADefinition());
342     if (auto *ToT0 = dyn_cast<TemplateDecl>(To0)) {
343       EXPECT_TRUE(ToT0->getTemplatedDecl());
344     }
345   }
346 
TypedTest_ImportDefinitionThenPrototypeclang::ast_matchers::RedeclChain347   void TypedTest_ImportDefinitionThenPrototype() {
348     Decl *FromTUDef = getTuDecl(getDefinition(), Lang_CXX03, "input0.cc");
349     Decl *FromTUProto = getTuDecl(getPrototype(), Lang_CXX03, "input1.cc");
350     auto *FromDef = FirstDeclMatcher<DeclTy>().match(FromTUDef, getPattern());
351     auto *FromProto =
352         FirstDeclMatcher<DeclTy>().match(FromTUProto, getPattern());
353     ASSERT_TRUE(FromDef->isThisDeclarationADefinition());
354     ASSERT_FALSE(FromProto->isThisDeclarationADefinition());
355 
356     Decl *ImportedDef = Import(FromDef, Lang_CXX03);
357     Decl *ImportedProto = Import(FromProto, Lang_CXX03);
358     Decl *ToTU = ImportedDef->getTranslationUnitDecl();
359 
360     EXPECT_NE(ImportedDef, ImportedProto);
361     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 2u);
362     auto *ToDef = FirstDeclMatcher<DeclTy>().match(ToTU, getPattern());
363     auto *ToProto = LastDeclMatcher<DeclTy>().match(ToTU, getPattern());
364     EXPECT_TRUE(ImportedDef == ToDef);
365     EXPECT_TRUE(ImportedProto == ToProto);
366     EXPECT_TRUE(ToDef->isThisDeclarationADefinition());
367     EXPECT_FALSE(ToProto->isThisDeclarationADefinition());
368 
369     CheckPreviousDecl(ToDef, ToProto);
370   }
371 
TypedTest_ImportPrototypeThenDefinitionclang::ast_matchers::RedeclChain372   void TypedTest_ImportPrototypeThenDefinition() {
373     Decl *FromTUProto = getTuDecl(getPrototype(), Lang_CXX03, "input0.cc");
374     Decl *FromTUDef = getTuDecl(getDefinition(), Lang_CXX03, "input1.cc");
375     auto *FromProto =
376         FirstDeclMatcher<DeclTy>().match(FromTUProto, getPattern());
377     auto *FromDef = FirstDeclMatcher<DeclTy>().match(FromTUDef, getPattern());
378     ASSERT_TRUE(FromDef->isThisDeclarationADefinition());
379     ASSERT_FALSE(FromProto->isThisDeclarationADefinition());
380 
381     Decl *ImportedProto = Import(FromProto, Lang_CXX03);
382     Decl *ImportedDef = Import(FromDef, Lang_CXX03);
383     Decl *ToTU = ImportedDef->getTranslationUnitDecl();
384 
385     EXPECT_NE(ImportedDef, ImportedProto);
386     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 2u);
387     auto *ToProto = FirstDeclMatcher<DeclTy>().match(ToTU, getPattern());
388     auto *ToDef = LastDeclMatcher<DeclTy>().match(ToTU, getPattern());
389     EXPECT_TRUE(ImportedDef == ToDef);
390     EXPECT_TRUE(ImportedProto == ToProto);
391     EXPECT_TRUE(ToDef->isThisDeclarationADefinition());
392     EXPECT_FALSE(ToProto->isThisDeclarationADefinition());
393 
394     CheckPreviousDecl(ToProto, ToDef);
395   }
396 
TypedTest_WholeRedeclChainIsImportedAtOnceclang::ast_matchers::RedeclChain397   void TypedTest_WholeRedeclChainIsImportedAtOnce() {
398     Decl *FromTU = getTuDecl(getPrototype() + getDefinition(), Lang_CXX03);
399     auto *FromD = // Definition
400         LastDeclMatcher<DeclTy>().match(FromTU, getPattern());
401     ASSERT_TRUE(FromD->isThisDeclarationADefinition());
402 
403     Decl *ImportedD = Import(FromD, Lang_CXX03);
404     Decl *ToTU = ImportedD->getTranslationUnitDecl();
405 
406     // The whole redecl chain is imported at once.
407     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 2u);
408     EXPECT_TRUE(cast<DeclTy>(ImportedD)->isThisDeclarationADefinition());
409   }
410 
TypedTest_ImportPrototypeThenProtoAndDefinitionclang::ast_matchers::RedeclChain411   void TypedTest_ImportPrototypeThenProtoAndDefinition() {
412     {
413       Decl *FromTU = getTuDecl(getPrototype(), Lang_CXX03, "input0.cc");
414       auto *FromD = FirstDeclMatcher<DeclTy>().match(FromTU, getPattern());
415       Import(FromD, Lang_CXX03);
416     }
417     {
418       Decl *FromTU =
419           getTuDecl(getPrototype() + getDefinition(), Lang_CXX03, "input1.cc");
420       auto *FromD = FirstDeclMatcher<DeclTy>().match(FromTU, getPattern());
421       Import(FromD, Lang_CXX03);
422     }
423 
424     Decl *ToTU = ToAST->getASTContext().getTranslationUnitDecl();
425 
426     ASSERT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 3u);
427     DeclTy *ProtoD = FirstDeclMatcher<DeclTy>().match(ToTU, getPattern());
428     EXPECT_FALSE(ProtoD->isThisDeclarationADefinition());
429 
430     DeclTy *DefinitionD = LastDeclMatcher<DeclTy>().match(ToTU, getPattern());
431     EXPECT_TRUE(DefinitionD->isThisDeclarationADefinition());
432 
433     EXPECT_TRUE(DefinitionD->getPreviousDecl());
434     EXPECT_FALSE(
435         DefinitionD->getPreviousDecl()->isThisDeclarationADefinition());
436 
437     CheckPreviousDecl(ProtoD, DefinitionD->getPreviousDecl());
438   }
439 };
440 
441 #define ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(BaseTemplate, TypeParam,       \
442                                                 NamePrefix, TestCase)          \
443   using BaseTemplate##TypeParam = BaseTemplate<TypeParam>;                     \
444   TEST_P(BaseTemplate##TypeParam, NamePrefix##TestCase) {                      \
445     TypedTest_##TestCase();                                                    \
446   }
447 
448 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(
449     RedeclChain, Function, ,
450     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
451 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(
452     RedeclChain, Class, ,
453     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
454 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(
455     RedeclChain, EnumClass, ,
456     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
457 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(
458     RedeclChain, Variable, ,
459     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
460 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(
461     RedeclChain, FunctionTemplate, ,
462     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
463 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(
464     RedeclChain, ClassTemplate, ,
465     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
466 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(
467     RedeclChain, VariableTemplate, ,
468     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
469 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(
470     RedeclChain, FunctionTemplateSpec, ,
471     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
472 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(
473     RedeclChain, ClassTemplateSpec, ,
474     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
475 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(
476     RedeclChain, VariableTemplateSpec, ,
477     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
478 
479 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Function, ,
480                                         DefinitionShouldBeImportedAsADefinition)
481 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Class, ,
482                                         DefinitionShouldBeImportedAsADefinition)
483 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, EnumClass, ,
484                                         DefinitionShouldBeImportedAsADefinition)
485 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Variable, ,
486                                         DefinitionShouldBeImportedAsADefinition)
487 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplate, ,
488                                         DefinitionShouldBeImportedAsADefinition)
489 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, ClassTemplate, ,
490                                         DefinitionShouldBeImportedAsADefinition)
491 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplate, ,
492                                         DefinitionShouldBeImportedAsADefinition)
493 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplateSpec, ,
494                                         DefinitionShouldBeImportedAsADefinition)
495 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, ClassTemplateSpec, ,
496                                         DefinitionShouldBeImportedAsADefinition)
497 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(
498     RedeclChain, VariableTemplateSpec, ,
499     DefinitionShouldBeImportedAsADefinition)
500 
501 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Function, ,
502                                         ImportPrototypeAfterImportedPrototype)
503 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Class, ,
504                                         ImportPrototypeAfterImportedPrototype)
505 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, EnumClass, ,
506                                         ImportPrototypeAfterImportedPrototype)
507 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Variable, ,
508                                         ImportPrototypeAfterImportedPrototype)
509 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplate, ,
510                                         ImportPrototypeAfterImportedPrototype)
511 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, ClassTemplate, ,
512                                         ImportPrototypeAfterImportedPrototype)
513 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplate, ,
514                                         ImportPrototypeAfterImportedPrototype)
515 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplateSpec, ,
516                                         ImportPrototypeAfterImportedPrototype)
517 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, ClassTemplateSpec, ,
518                                         ImportPrototypeAfterImportedPrototype)
519 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplateSpec, ,
520                                          ImportPrototypeAfterImportedPrototype)
521 
522 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Function, ,
523                                         ImportDefinitionAfterImportedPrototype)
524 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Class, ,
525                                         ImportDefinitionAfterImportedPrototype)
526 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, EnumClass, ,
527                                         ImportDefinitionAfterImportedPrototype)
528 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Variable, ,
529                                         ImportDefinitionAfterImportedPrototype)
530 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplate, ,
531                                         ImportDefinitionAfterImportedPrototype)
532 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, ClassTemplate, ,
533                                         ImportDefinitionAfterImportedPrototype)
534 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplate, ,
535                                         ImportDefinitionAfterImportedPrototype)
536 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplateSpec, ,
537                                         ImportDefinitionAfterImportedPrototype)
538 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, ClassTemplateSpec, ,
539                                         ImportDefinitionAfterImportedPrototype)
540 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplateSpec, ,
541                                          ImportDefinitionAfterImportedPrototype)
542 
543 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Function, ,
544                                         ImportPrototypeAfterImportedDefinition)
545 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Class, ,
546                                         ImportPrototypeAfterImportedDefinition)
547 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, EnumClass, ,
548                                         ImportPrototypeAfterImportedDefinition)
549 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Variable, ,
550                                         ImportPrototypeAfterImportedDefinition)
551 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplate, ,
552                                         ImportPrototypeAfterImportedDefinition)
553 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, ClassTemplate, ,
554                                         ImportPrototypeAfterImportedDefinition)
555 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplate, ,
556                                         ImportPrototypeAfterImportedDefinition)
557 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplateSpec, ,
558                                         ImportPrototypeAfterImportedDefinition)
559 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, ClassTemplateSpec, ,
560                                         ImportPrototypeAfterImportedDefinition)
561 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplateSpec, ,
562                                          ImportPrototypeAfterImportedDefinition)
563 
564 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Function, ,
565                                         ImportPrototypes)
566 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Class, , ImportPrototypes)
567 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, EnumClass, ,
568                                         ImportPrototypes)
569 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Variable, ,
570                                         ImportPrototypes)
571 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplate, ,
572                                         ImportPrototypes)
573 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, ClassTemplate, ,
574                                         ImportPrototypes)
575 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplate, ,
576                                         ImportPrototypes)
577 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, ClassTemplateSpec, ,
578                                         ImportPrototypes)
579 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplateSpec, ,
580                                         ImportPrototypes)
581 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplateSpec, ,
582                                          ImportPrototypes)
583 
584 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Function, ,
585                                         ImportDefinitions)
586 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Class, , ImportDefinitions)
587 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, EnumClass, ,
588                                         ImportDefinitions)
589 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Variable, ,
590                                         ImportDefinitions)
591 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplate, ,
592                                         ImportDefinitions)
593 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, ClassTemplate, ,
594                                         ImportDefinitions)
595 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplate, ,
596                                         ImportDefinitions)
597 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, ClassTemplateSpec, ,
598                                         ImportDefinitions)
599 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplateSpec, ,
600                                         ImportDefinitions)
601 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplateSpec, ,
602                                          ImportDefinitions)
603 
604 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Function, ,
605                                         ImportDefinitionThenPrototype)
606 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Class, ,
607                                         ImportDefinitionThenPrototype)
608 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, EnumClass, ,
609                                         ImportDefinitionThenPrototype)
610 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Variable, ,
611                                         ImportDefinitionThenPrototype)
612 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplate, ,
613                                         ImportDefinitionThenPrototype)
614 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, ClassTemplate, ,
615                                         ImportDefinitionThenPrototype)
616 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplate, ,
617                                         ImportDefinitionThenPrototype)
618 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplateSpec, ,
619                                         ImportDefinitionThenPrototype)
620 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, ClassTemplateSpec, ,
621                                         ImportDefinitionThenPrototype)
622 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplateSpec, ,
623                                          ImportDefinitionThenPrototype)
624 
625 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Function, ,
626                                         ImportPrototypeThenDefinition)
627 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Class, ,
628                                         ImportPrototypeThenDefinition)
629 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, EnumClass, ,
630                                         ImportPrototypeThenDefinition)
631 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Variable, ,
632                                         ImportPrototypeThenDefinition)
633 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplate, ,
634                                         ImportPrototypeThenDefinition)
635 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, ClassTemplate, ,
636                                         ImportPrototypeThenDefinition)
637 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplate, ,
638                                         ImportPrototypeThenDefinition)
639 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplateSpec, ,
640                                         ImportPrototypeThenDefinition)
641 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, ClassTemplateSpec, ,
642                                         ImportPrototypeThenDefinition)
643 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplateSpec, ,
644                                          ImportPrototypeThenDefinition)
645 
646 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Function, ,
647                                         WholeRedeclChainIsImportedAtOnce)
648 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Variable, ,
649                                         WholeRedeclChainIsImportedAtOnce)
650 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplate, ,
651                                         WholeRedeclChainIsImportedAtOnce)
652 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplate, ,
653                                         WholeRedeclChainIsImportedAtOnce)
654 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplateSpec, ,
655                                         WholeRedeclChainIsImportedAtOnce)
656 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplateSpec, ,
657                                          WholeRedeclChainIsImportedAtOnce)
658 
659 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Function, ,
660                                         ImportPrototypeThenProtoAndDefinition)
661 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, Variable, ,
662                                         ImportPrototypeThenProtoAndDefinition)
663 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplate, ,
664                                         ImportPrototypeThenProtoAndDefinition)
665 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplate, ,
666                                         ImportPrototypeThenProtoAndDefinition)
667 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, FunctionTemplateSpec, ,
668                                         ImportPrototypeThenProtoAndDefinition)
669 ASTIMPORTER_INSTANTIATE_TYPED_TEST_SUITE(RedeclChain, VariableTemplateSpec, ,
670                                          ImportPrototypeThenProtoAndDefinition)
671 
672 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, RedeclChainFunction,
673                         DefaultTestValuesForRunOptions);
674 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, RedeclChainClass,
675                         DefaultTestValuesForRunOptions);
676 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, RedeclChainEnumClass,
677                         DefaultTestValuesForRunOptions);
678 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, RedeclChainVariable,
679                         DefaultTestValuesForRunOptions);
680 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, RedeclChainFunctionTemplate,
681                         DefaultTestValuesForRunOptions);
682 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, RedeclChainClassTemplate,
683                         DefaultTestValuesForRunOptions);
684 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, RedeclChainVariableTemplate,
685                         DefaultTestValuesForRunOptions);
686 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, RedeclChainFunctionTemplateSpec,
687                         DefaultTestValuesForRunOptions);
688 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, RedeclChainClassTemplateSpec,
689                         DefaultTestValuesForRunOptions);
690 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, RedeclChainVariableTemplateSpec,
691                          DefaultTestValuesForRunOptions);
692 
693 } // end namespace ast_matchers
694 } // end namespace clang
695