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       template <> int X<int>;
84       )";
85   // There is no matcher for varTemplateDecl so use a work-around.
getPatternclang::ast_matchers::VariableTemplate86   BindableMatcher<Decl> getPattern() {
87     return namedDecl(hasName("X"), unless(isImplicit()),
88                      has(templateTypeParmDecl()));
89   }
90 };
91 
92 struct FunctionTemplateSpec {
93   using DeclTy = FunctionDecl;
94   static constexpr auto *Prototype =
95       R"(
96       // Proto of the primary template.
97       template <class T>
98       void X();
99       // Proto of the specialization.
100       template <>
101       void X<int>();
102       )";
103   static constexpr auto *Definition =
104       R"(
105       // Proto of the primary template.
106       template <class T>
107       void X();
108       // Specialization and definition.
109       template <>
110       void X<int>() {}
111       )";
getPatternclang::ast_matchers::FunctionTemplateSpec112   BindableMatcher<Decl> getPattern() {
113     return functionDecl(hasName("X"), isExplicitTemplateSpecialization());
114   }
115 };
116 
117 struct ClassTemplateSpec {
118   using DeclTy = ClassTemplateSpecializationDecl;
119   static constexpr auto *Prototype =
120       R"(
121     template <class T> class X;
122     template <> class X<int>;
123     )";
124   static constexpr auto *Definition =
125       R"(
126     template <class T> class X;
127     template <> class X<int> {};
128     )";
getPatternclang::ast_matchers::ClassTemplateSpec129   BindableMatcher<Decl> getPattern() {
130     return classTemplateSpecializationDecl(hasName("X"), unless(isImplicit()));
131   }
132 };
133 
134 template <typename TypeParam>
135 struct RedeclChain : ASTImporterOptionSpecificTestBase {
136 
137   using DeclTy = typename TypeParam::DeclTy;
getPrototypeclang::ast_matchers::RedeclChain138   std::string getPrototype() { return TypeParam::Prototype; }
getDefinitionclang::ast_matchers::RedeclChain139   std::string getDefinition() { return TypeParam::Definition; }
getPatternclang::ast_matchers::RedeclChain140   BindableMatcher<Decl> getPattern() const { return TypeParam().getPattern(); }
141 
CheckPreviousDeclclang::ast_matchers::RedeclChain142   void CheckPreviousDecl(Decl *Prev, Decl *Current) {
143     ASSERT_NE(Prev, Current);
144     ASSERT_EQ(&Prev->getASTContext(), &Current->getASTContext());
145     EXPECT_EQ(Prev->getCanonicalDecl(), Current->getCanonicalDecl());
146 
147     // Templates.
148     if (auto *PrevT = dyn_cast<TemplateDecl>(Prev)) {
149       EXPECT_EQ(Current->getPreviousDecl(), Prev);
150       auto *CurrentT = cast<TemplateDecl>(Current);
151       ASSERT_TRUE(PrevT->getTemplatedDecl());
152       ASSERT_TRUE(CurrentT->getTemplatedDecl());
153       EXPECT_EQ(CurrentT->getTemplatedDecl()->getPreviousDecl(),
154                 PrevT->getTemplatedDecl());
155       return;
156     }
157 
158     // Specializations.
159     if (auto *PrevF = dyn_cast<FunctionDecl>(Prev)) {
160       if (PrevF->getTemplatedKind() ==
161           FunctionDecl::TK_FunctionTemplateSpecialization) {
162         // There may be a hidden fwd spec decl before a spec decl.
163         // In that case the previous visible decl can be reached through that
164         // invisible one.
165         EXPECT_THAT(Prev, testing::AnyOf(
166                               Current->getPreviousDecl(),
167                               Current->getPreviousDecl()->getPreviousDecl()));
168         auto *ToTU = Prev->getTranslationUnitDecl();
169         auto *TemplateD = FirstDeclMatcher<FunctionTemplateDecl>().match(
170             ToTU, functionTemplateDecl());
171         auto *FirstSpecD = *(TemplateD->spec_begin());
172         EXPECT_EQ(FirstSpecD->getCanonicalDecl(), PrevF->getCanonicalDecl());
173         return;
174       }
175     }
176 
177     // The rest: Classes, Functions, etc.
178     EXPECT_EQ(Current->getPreviousDecl(), Prev);
179   }
180 
181   void
TypedTest_PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinitionclang::ast_matchers::RedeclChain182   TypedTest_PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition() {
183     Decl *FromTU = getTuDecl(getPrototype(), Lang_CXX03);
184     auto *FromD = FirstDeclMatcher<DeclTy>().match(FromTU, getPattern());
185     ASSERT_FALSE(FromD->isThisDeclarationADefinition());
186 
187     Decl *ImportedD = Import(FromD, Lang_CXX03);
188     Decl *ToTU = ImportedD->getTranslationUnitDecl();
189 
190     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 1u);
191     auto *ToD = LastDeclMatcher<DeclTy>().match(ToTU, getPattern());
192     EXPECT_TRUE(ImportedD == ToD);
193     EXPECT_FALSE(ToD->isThisDeclarationADefinition());
194     if (auto *ToT = dyn_cast<TemplateDecl>(ToD)) {
195       EXPECT_TRUE(ToT->getTemplatedDecl());
196     }
197   }
198 
TypedTest_DefinitionShouldBeImportedAsADefinitionclang::ast_matchers::RedeclChain199   void TypedTest_DefinitionShouldBeImportedAsADefinition() {
200     Decl *FromTU = getTuDecl(getDefinition(), Lang_CXX03);
201     auto *FromD = FirstDeclMatcher<DeclTy>().match(FromTU, getPattern());
202     ASSERT_TRUE(FromD->isThisDeclarationADefinition());
203 
204     Decl *ImportedD = Import(FromD, Lang_CXX03);
205     Decl *ToTU = ImportedD->getTranslationUnitDecl();
206 
207     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 1u);
208     auto *ToD = LastDeclMatcher<DeclTy>().match(ToTU, getPattern());
209     EXPECT_TRUE(ToD->isThisDeclarationADefinition());
210     if (auto *ToT = dyn_cast<TemplateDecl>(ToD)) {
211       EXPECT_TRUE(ToT->getTemplatedDecl());
212     }
213   }
214 
TypedTest_ImportPrototypeAfterImportedPrototypeclang::ast_matchers::RedeclChain215   void TypedTest_ImportPrototypeAfterImportedPrototype() {
216     Decl *FromTU = getTuDecl(getPrototype() + getPrototype(), Lang_CXX03);
217     auto *From0 = FirstDeclMatcher<DeclTy>().match(FromTU, getPattern());
218     auto *From1 = LastDeclMatcher<DeclTy>().match(FromTU, getPattern());
219     ASSERT_FALSE(From0->isThisDeclarationADefinition());
220     ASSERT_FALSE(From1->isThisDeclarationADefinition());
221 
222     Decl *Imported0 = Import(From0, Lang_CXX03);
223     Decl *Imported1 = Import(From1, Lang_CXX03);
224     Decl *ToTU = Imported0->getTranslationUnitDecl();
225 
226     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 2u);
227     auto *To0 = FirstDeclMatcher<DeclTy>().match(ToTU, getPattern());
228     auto *To1 = LastDeclMatcher<DeclTy>().match(ToTU, getPattern());
229     EXPECT_TRUE(Imported0 == To0);
230     EXPECT_TRUE(Imported1 == To1);
231     EXPECT_FALSE(To0->isThisDeclarationADefinition());
232     EXPECT_FALSE(To1->isThisDeclarationADefinition());
233 
234     CheckPreviousDecl(To0, To1);
235   }
236 
TypedTest_ImportDefinitionAfterImportedPrototypeclang::ast_matchers::RedeclChain237   void TypedTest_ImportDefinitionAfterImportedPrototype() {
238     Decl *FromTU = getTuDecl(getPrototype() + getDefinition(), Lang_CXX03);
239     auto *FromProto = FirstDeclMatcher<DeclTy>().match(FromTU, getPattern());
240     auto *FromDef = LastDeclMatcher<DeclTy>().match(FromTU, getPattern());
241     ASSERT_FALSE(FromProto->isThisDeclarationADefinition());
242     ASSERT_TRUE(FromDef->isThisDeclarationADefinition());
243 
244     Decl *ImportedProto = Import(FromProto, Lang_CXX03);
245     Decl *ImportedDef = Import(FromDef, Lang_CXX03);
246     Decl *ToTU = ImportedProto->getTranslationUnitDecl();
247 
248     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 2u);
249     auto *ToProto = FirstDeclMatcher<DeclTy>().match(ToTU, getPattern());
250     auto *ToDef = LastDeclMatcher<DeclTy>().match(ToTU, getPattern());
251     EXPECT_TRUE(ImportedProto == ToProto);
252     EXPECT_TRUE(ImportedDef == ToDef);
253     EXPECT_FALSE(ToProto->isThisDeclarationADefinition());
254     EXPECT_TRUE(ToDef->isThisDeclarationADefinition());
255 
256     CheckPreviousDecl(ToProto, ToDef);
257   }
258 
TypedTest_ImportPrototypeAfterImportedDefinitionclang::ast_matchers::RedeclChain259   void TypedTest_ImportPrototypeAfterImportedDefinition() {
260     Decl *FromTU = getTuDecl(getDefinition() + getPrototype(), Lang_CXX03);
261     auto *FromDef = FirstDeclMatcher<DeclTy>().match(FromTU, getPattern());
262     auto *FromProto = LastDeclMatcher<DeclTy>().match(FromTU, getPattern());
263     ASSERT_TRUE(FromDef->isThisDeclarationADefinition());
264     ASSERT_FALSE(FromProto->isThisDeclarationADefinition());
265 
266     Decl *ImportedDef = Import(FromDef, Lang_CXX03);
267     Decl *ImportedProto = Import(FromProto, Lang_CXX03);
268     Decl *ToTU = ImportedDef->getTranslationUnitDecl();
269 
270     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 2u);
271     auto *ToDef = FirstDeclMatcher<DeclTy>().match(ToTU, getPattern());
272     auto *ToProto = LastDeclMatcher<DeclTy>().match(ToTU, getPattern());
273     EXPECT_TRUE(ImportedDef == ToDef);
274     EXPECT_TRUE(ImportedProto == ToProto);
275     EXPECT_TRUE(ToDef->isThisDeclarationADefinition());
276     EXPECT_FALSE(ToProto->isThisDeclarationADefinition());
277 
278     CheckPreviousDecl(ToDef, ToProto);
279   }
280 
TypedTest_ImportPrototypesclang::ast_matchers::RedeclChain281   void TypedTest_ImportPrototypes() {
282     Decl *FromTU0 = getTuDecl(getPrototype(), Lang_CXX03, "input0.cc");
283     Decl *FromTU1 = getTuDecl(getPrototype(), Lang_CXX03, "input1.cc");
284     auto *From0 = FirstDeclMatcher<DeclTy>().match(FromTU0, getPattern());
285     auto *From1 = FirstDeclMatcher<DeclTy>().match(FromTU1, getPattern());
286     ASSERT_FALSE(From0->isThisDeclarationADefinition());
287     ASSERT_FALSE(From1->isThisDeclarationADefinition());
288 
289     Decl *Imported0 = Import(From0, Lang_CXX03);
290     Decl *Imported1 = Import(From1, Lang_CXX03);
291     Decl *ToTU = Imported0->getTranslationUnitDecl();
292 
293     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 2u);
294     auto *To0 = FirstDeclMatcher<DeclTy>().match(ToTU, getPattern());
295     auto *To1 = LastDeclMatcher<DeclTy>().match(ToTU, getPattern());
296     EXPECT_TRUE(Imported0 == To0);
297     EXPECT_TRUE(Imported1 == To1);
298     EXPECT_FALSE(To0->isThisDeclarationADefinition());
299     EXPECT_FALSE(To1->isThisDeclarationADefinition());
300 
301     CheckPreviousDecl(To0, To1);
302   }
303 
TypedTest_ImportDefinitionsclang::ast_matchers::RedeclChain304   void TypedTest_ImportDefinitions() {
305     Decl *FromTU0 = getTuDecl(getDefinition(), Lang_CXX03, "input0.cc");
306     Decl *FromTU1 = getTuDecl(getDefinition(), Lang_CXX03, "input1.cc");
307     auto *From0 = FirstDeclMatcher<DeclTy>().match(FromTU0, getPattern());
308     auto *From1 = FirstDeclMatcher<DeclTy>().match(FromTU1, getPattern());
309     ASSERT_TRUE(From0->isThisDeclarationADefinition());
310     ASSERT_TRUE(From1->isThisDeclarationADefinition());
311 
312     Decl *Imported0 = Import(From0, Lang_CXX03);
313     Decl *Imported1 = Import(From1, Lang_CXX03);
314     Decl *ToTU = Imported0->getTranslationUnitDecl();
315 
316     EXPECT_EQ(Imported0, Imported1);
317     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 1u);
318     auto *To0 = FirstDeclMatcher<DeclTy>().match(ToTU, getPattern());
319     EXPECT_TRUE(Imported0 == To0);
320     EXPECT_TRUE(To0->isThisDeclarationADefinition());
321     if (auto *ToT0 = dyn_cast<TemplateDecl>(To0)) {
322       EXPECT_TRUE(ToT0->getTemplatedDecl());
323     }
324   }
325 
TypedTest_ImportDefinitionThenPrototypeclang::ast_matchers::RedeclChain326   void TypedTest_ImportDefinitionThenPrototype() {
327     Decl *FromTUDef = getTuDecl(getDefinition(), Lang_CXX03, "input0.cc");
328     Decl *FromTUProto = getTuDecl(getPrototype(), Lang_CXX03, "input1.cc");
329     auto *FromDef = FirstDeclMatcher<DeclTy>().match(FromTUDef, getPattern());
330     auto *FromProto =
331         FirstDeclMatcher<DeclTy>().match(FromTUProto, getPattern());
332     ASSERT_TRUE(FromDef->isThisDeclarationADefinition());
333     ASSERT_FALSE(FromProto->isThisDeclarationADefinition());
334 
335     Decl *ImportedDef = Import(FromDef, Lang_CXX03);
336     Decl *ImportedProto = Import(FromProto, Lang_CXX03);
337     Decl *ToTU = ImportedDef->getTranslationUnitDecl();
338 
339     EXPECT_NE(ImportedDef, ImportedProto);
340     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 2u);
341     auto *ToDef = FirstDeclMatcher<DeclTy>().match(ToTU, getPattern());
342     auto *ToProto = LastDeclMatcher<DeclTy>().match(ToTU, getPattern());
343     EXPECT_TRUE(ImportedDef == ToDef);
344     EXPECT_TRUE(ImportedProto == ToProto);
345     EXPECT_TRUE(ToDef->isThisDeclarationADefinition());
346     EXPECT_FALSE(ToProto->isThisDeclarationADefinition());
347 
348     CheckPreviousDecl(ToDef, ToProto);
349   }
350 
TypedTest_ImportPrototypeThenDefinitionclang::ast_matchers::RedeclChain351   void TypedTest_ImportPrototypeThenDefinition() {
352     Decl *FromTUProto = getTuDecl(getPrototype(), Lang_CXX03, "input0.cc");
353     Decl *FromTUDef = getTuDecl(getDefinition(), Lang_CXX03, "input1.cc");
354     auto *FromProto =
355         FirstDeclMatcher<DeclTy>().match(FromTUProto, getPattern());
356     auto *FromDef = FirstDeclMatcher<DeclTy>().match(FromTUDef, getPattern());
357     ASSERT_TRUE(FromDef->isThisDeclarationADefinition());
358     ASSERT_FALSE(FromProto->isThisDeclarationADefinition());
359 
360     Decl *ImportedProto = Import(FromProto, Lang_CXX03);
361     Decl *ImportedDef = Import(FromDef, Lang_CXX03);
362     Decl *ToTU = ImportedDef->getTranslationUnitDecl();
363 
364     EXPECT_NE(ImportedDef, ImportedProto);
365     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 2u);
366     auto *ToProto = FirstDeclMatcher<DeclTy>().match(ToTU, getPattern());
367     auto *ToDef = LastDeclMatcher<DeclTy>().match(ToTU, getPattern());
368     EXPECT_TRUE(ImportedDef == ToDef);
369     EXPECT_TRUE(ImportedProto == ToProto);
370     EXPECT_TRUE(ToDef->isThisDeclarationADefinition());
371     EXPECT_FALSE(ToProto->isThisDeclarationADefinition());
372 
373     CheckPreviousDecl(ToProto, ToDef);
374   }
375 
TypedTest_WholeRedeclChainIsImportedAtOnceclang::ast_matchers::RedeclChain376   void TypedTest_WholeRedeclChainIsImportedAtOnce() {
377     Decl *FromTU = getTuDecl(getPrototype() + getDefinition(), Lang_CXX03);
378     auto *FromD = // Definition
379         LastDeclMatcher<DeclTy>().match(FromTU, getPattern());
380     ASSERT_TRUE(FromD->isThisDeclarationADefinition());
381 
382     Decl *ImportedD = Import(FromD, Lang_CXX03);
383     Decl *ToTU = ImportedD->getTranslationUnitDecl();
384 
385     // The whole redecl chain is imported at once.
386     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 2u);
387     EXPECT_TRUE(cast<DeclTy>(ImportedD)->isThisDeclarationADefinition());
388   }
389 
TypedTest_ImportPrototypeThenProtoAndDefinitionclang::ast_matchers::RedeclChain390   void TypedTest_ImportPrototypeThenProtoAndDefinition() {
391     {
392       Decl *FromTU = getTuDecl(getPrototype(), Lang_CXX03, "input0.cc");
393       auto *FromD = FirstDeclMatcher<DeclTy>().match(FromTU, getPattern());
394       Import(FromD, Lang_CXX03);
395     }
396     {
397       Decl *FromTU =
398           getTuDecl(getPrototype() + getDefinition(), Lang_CXX03, "input1.cc");
399       auto *FromD = FirstDeclMatcher<DeclTy>().match(FromTU, getPattern());
400       Import(FromD, Lang_CXX03);
401     }
402 
403     Decl *ToTU = ToAST->getASTContext().getTranslationUnitDecl();
404 
405     ASSERT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 3u);
406     DeclTy *ProtoD = FirstDeclMatcher<DeclTy>().match(ToTU, getPattern());
407     EXPECT_FALSE(ProtoD->isThisDeclarationADefinition());
408 
409     DeclTy *DefinitionD = LastDeclMatcher<DeclTy>().match(ToTU, getPattern());
410     EXPECT_TRUE(DefinitionD->isThisDeclarationADefinition());
411 
412     EXPECT_TRUE(DefinitionD->getPreviousDecl());
413     EXPECT_FALSE(
414         DefinitionD->getPreviousDecl()->isThisDeclarationADefinition());
415 
416     CheckPreviousDecl(ProtoD, DefinitionD->getPreviousDecl());
417   }
418 };
419 
420 #define ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(BaseTemplate, TypeParam,       \
421                                                 NamePrefix, TestCase)          \
422   using BaseTemplate##TypeParam = BaseTemplate<TypeParam>;                     \
423   TEST_P(BaseTemplate##TypeParam, NamePrefix##TestCase) {                      \
424     TypedTest_##TestCase();                                                    \
425   }
426 
427 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(
428     RedeclChain, Function, ,
429     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
430 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(
431     RedeclChain, Class, ,
432     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
433 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(
434     RedeclChain, EnumClass, ,
435     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
436 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(
437     RedeclChain, Variable, ,
438     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
439 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(
440     RedeclChain, FunctionTemplate, ,
441     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
442 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(
443     RedeclChain, ClassTemplate, ,
444     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
445 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(
446     RedeclChain, VariableTemplate, ,
447     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
448 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(
449     RedeclChain, FunctionTemplateSpec, ,
450     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
451 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(
452     RedeclChain, ClassTemplateSpec, ,
453     PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
454 
455 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Function, ,
456                                         DefinitionShouldBeImportedAsADefinition)
457 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Class, ,
458                                         DefinitionShouldBeImportedAsADefinition)
459 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, EnumClass, ,
460                                         DefinitionShouldBeImportedAsADefinition)
461 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Variable, ,
462                                         DefinitionShouldBeImportedAsADefinition)
463 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplate, ,
464                                         DefinitionShouldBeImportedAsADefinition)
465 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplate, ,
466                                         DefinitionShouldBeImportedAsADefinition)
467 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, VariableTemplate, ,
468                                         DefinitionShouldBeImportedAsADefinition)
469 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplateSpec, ,
470                                         DefinitionShouldBeImportedAsADefinition)
471 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplateSpec, ,
472                                         DefinitionShouldBeImportedAsADefinition)
473 
474 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Function, ,
475                                         ImportPrototypeAfterImportedPrototype)
476 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Class, ,
477                                         ImportPrototypeAfterImportedPrototype)
478 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, EnumClass, ,
479                                         ImportPrototypeAfterImportedPrototype)
480 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Variable, ,
481                                         ImportPrototypeAfterImportedPrototype)
482 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplate, ,
483                                         ImportPrototypeAfterImportedPrototype)
484 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplate, ,
485                                         ImportPrototypeAfterImportedPrototype)
486 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, VariableTemplate, ,
487                                         ImportPrototypeAfterImportedPrototype)
488 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplateSpec, ,
489                                         ImportPrototypeAfterImportedPrototype)
490 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplateSpec, ,
491                                         ImportPrototypeAfterImportedPrototype)
492 
493 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Function, ,
494                                         ImportDefinitionAfterImportedPrototype)
495 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Class, ,
496                                         ImportDefinitionAfterImportedPrototype)
497 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, EnumClass, ,
498                                         ImportDefinitionAfterImportedPrototype)
499 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Variable, ,
500                                         ImportDefinitionAfterImportedPrototype)
501 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplate, ,
502                                         ImportDefinitionAfterImportedPrototype)
503 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplate, ,
504                                         ImportDefinitionAfterImportedPrototype)
505 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, VariableTemplate, ,
506                                         ImportDefinitionAfterImportedPrototype)
507 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplateSpec, ,
508                                         ImportDefinitionAfterImportedPrototype)
509 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplateSpec, ,
510                                         ImportDefinitionAfterImportedPrototype)
511 
512 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Function, ,
513                                         ImportPrototypeAfterImportedDefinition)
514 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Class, ,
515                                         ImportPrototypeAfterImportedDefinition)
516 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, EnumClass, ,
517                                         ImportPrototypeAfterImportedDefinition)
518 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Variable, ,
519                                         ImportPrototypeAfterImportedDefinition)
520 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplate, ,
521                                         ImportPrototypeAfterImportedDefinition)
522 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplate, ,
523                                         ImportPrototypeAfterImportedDefinition)
524 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, VariableTemplate, ,
525                                         ImportPrototypeAfterImportedDefinition)
526 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplateSpec, ,
527                                         ImportPrototypeAfterImportedDefinition)
528 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplateSpec, ,
529                                         ImportPrototypeAfterImportedDefinition)
530 
531 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Function, ,
532                                         ImportPrototypes)
533 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Class, , ImportPrototypes)
534 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, EnumClass, ,
535                                         ImportPrototypes)
536 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Variable, ,
537                                         ImportPrototypes)
538 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplate, ,
539                                         ImportPrototypes)
540 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplate, ,
541                                         ImportPrototypes)
542 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, VariableTemplate, ,
543                                         ImportPrototypes)
544 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplateSpec, ,
545                                         ImportPrototypes)
546 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplateSpec, ,
547                                         ImportPrototypes)
548 
549 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Function, ,
550                                         ImportDefinitions)
551 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Class, , ImportDefinitions)
552 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, EnumClass, ,
553                                         ImportDefinitions)
554 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Variable, ,
555                                         ImportDefinitions)
556 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplate, ,
557                                         ImportDefinitions)
558 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplate, ,
559                                         ImportDefinitions)
560 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, VariableTemplate, ,
561                                         ImportDefinitions)
562 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplateSpec, ,
563                                         ImportDefinitions)
564 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplateSpec, ,
565                                         ImportDefinitions)
566 
567 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Function, ,
568                                         ImportDefinitionThenPrototype)
569 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Class, ,
570                                         ImportDefinitionThenPrototype)
571 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, EnumClass, ,
572                                         ImportDefinitionThenPrototype)
573 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Variable, ,
574                                         ImportDefinitionThenPrototype)
575 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplate, ,
576                                         ImportDefinitionThenPrototype)
577 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplate, ,
578                                         ImportDefinitionThenPrototype)
579 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, VariableTemplate, ,
580                                         ImportDefinitionThenPrototype)
581 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplateSpec, ,
582                                         ImportDefinitionThenPrototype)
583 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplateSpec, ,
584                                         ImportDefinitionThenPrototype)
585 
586 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Function, ,
587                                         ImportPrototypeThenDefinition)
588 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Class, ,
589                                         ImportPrototypeThenDefinition)
590 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, EnumClass, ,
591                                         ImportPrototypeThenDefinition)
592 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Variable, ,
593                                         ImportPrototypeThenDefinition)
594 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplate, ,
595                                         ImportPrototypeThenDefinition)
596 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplate, ,
597                                         ImportPrototypeThenDefinition)
598 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, VariableTemplate, ,
599                                         ImportPrototypeThenDefinition)
600 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplateSpec, ,
601                                         ImportPrototypeThenDefinition)
602 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplateSpec, ,
603                                         ImportPrototypeThenDefinition)
604 
605 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Function, ,
606                                         WholeRedeclChainIsImportedAtOnce)
607 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Variable, ,
608                                         WholeRedeclChainIsImportedAtOnce)
609 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplate, ,
610                                         WholeRedeclChainIsImportedAtOnce)
611 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, VariableTemplate, ,
612                                         WholeRedeclChainIsImportedAtOnce)
613 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplateSpec, ,
614                                         WholeRedeclChainIsImportedAtOnce)
615 
616 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Function, ,
617                                         ImportPrototypeThenProtoAndDefinition)
618 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, Variable, ,
619                                         ImportPrototypeThenProtoAndDefinition)
620 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplate, ,
621                                         ImportPrototypeThenProtoAndDefinition)
622 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, VariableTemplate, ,
623                                         ImportPrototypeThenProtoAndDefinition)
624 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplateSpec, ,
625                                         ImportPrototypeThenProtoAndDefinition)
626 
627 INSTANTIATE_TEST_CASE_P(ParameterizedTests, RedeclChainFunction,
628                         DefaultTestValuesForRunOptions, );
629 INSTANTIATE_TEST_CASE_P(ParameterizedTests, RedeclChainClass,
630                         DefaultTestValuesForRunOptions, );
631 INSTANTIATE_TEST_CASE_P(ParameterizedTests, RedeclChainEnumClass,
632                         DefaultTestValuesForRunOptions, );
633 INSTANTIATE_TEST_CASE_P(ParameterizedTests, RedeclChainVariable,
634                         DefaultTestValuesForRunOptions, );
635 INSTANTIATE_TEST_CASE_P(ParameterizedTests, RedeclChainFunctionTemplate,
636                         DefaultTestValuesForRunOptions, );
637 INSTANTIATE_TEST_CASE_P(ParameterizedTests, RedeclChainClassTemplate,
638                         DefaultTestValuesForRunOptions, );
639 INSTANTIATE_TEST_CASE_P(ParameterizedTests, RedeclChainVariableTemplate,
640                         DefaultTestValuesForRunOptions, );
641 INSTANTIATE_TEST_CASE_P(ParameterizedTests, RedeclChainFunctionTemplateSpec,
642                         DefaultTestValuesForRunOptions, );
643 INSTANTIATE_TEST_CASE_P(ParameterizedTests, RedeclChainClassTemplateSpec,
644                         DefaultTestValuesForRunOptions, );
645 
646 } // end namespace ast_matchers
647 } // end namespace clang
648