1 //===- unittest/AST/ASTImporterODRStrategiesTest.cpp -----------------------===//
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 to verify the import behaviour in case of ODR
10 // violation.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "ASTImporterFixtures.h"
15 
16 namespace clang {
17 namespace ast_matchers {
18 
19 using internal::BindableMatcher;
20 
21 // DeclTy: Type of the Decl to check.
22 // Prototype: "Prototype" (forward declaration) of the Decl.
23 // Definition: A definition for the Prototype.
24 // ConflictingPrototype: A prototype with the same name but different
25 // declaration.
26 // ConflictingDefinition: A different definition for Prototype.
27 // ConflictingProtoDef: A definition for ConflictingPrototype.
28 // getPattern: Return a matcher that matches any of Prototype, Definition,
29 // ConflictingPrototype, ConflictingDefinition, ConflictingProtoDef.
30 
31 struct Function {
32   using DeclTy = FunctionDecl;
33   static constexpr auto *Prototype = "void X(int);";
34   static constexpr auto *ConflictingPrototype = "void X(double);";
35   static constexpr auto *Definition = "void X(int a) {}";
36   static constexpr auto *ConflictingDefinition = "void X(double a) {}";
getPatternclang::ast_matchers::Function37   BindableMatcher<Decl> getPattern() {
38     return functionDecl(hasName("X"), unless(isImplicit()));
39   }
getLangclang::ast_matchers::Function40   Language getLang() { return Lang_C; }
41 };
42 
43 struct Typedef {
44   using DeclTy = TypedefNameDecl;
45   static constexpr auto *Definition = "typedef int X;";
46   static constexpr auto *ConflictingDefinition = "typedef double X;";
getPatternclang::ast_matchers::Typedef47   BindableMatcher<Decl> getPattern() { return typedefNameDecl(hasName("X")); }
getLangclang::ast_matchers::Typedef48   Language getLang() { return Lang_CXX; }
49 };
50 
51 struct TypedefAlias {
52   using DeclTy = TypedefNameDecl;
53   static constexpr auto *Definition = "using X = int;";
54   static constexpr auto *ConflictingDefinition = "using X = double;";
getPatternclang::ast_matchers::TypedefAlias55   BindableMatcher<Decl> getPattern() { return typedefNameDecl(hasName("X")); }
getLangclang::ast_matchers::TypedefAlias56   Language getLang() { return Lang_CXX11; }
57 };
58 
59 struct Enum {
60   using DeclTy = EnumDecl;
61   static constexpr auto *Definition = "enum X { a, b };";
62   static constexpr auto *ConflictingDefinition = "enum X { a, b, c };";
getPatternclang::ast_matchers::Enum63   BindableMatcher<Decl> getPattern() { return enumDecl(hasName("X")); }
getLangclang::ast_matchers::Enum64   Language getLang() { return Lang_CXX; }
65 };
66 
67 struct EnumConstant {
68   using DeclTy = EnumConstantDecl;
69   static constexpr auto *Definition = "enum E { X = 0 };";
70   static constexpr auto *ConflictingDefinition = "enum E { X = 1 };";
getPatternclang::ast_matchers::EnumConstant71   BindableMatcher<Decl> getPattern() { return enumConstantDecl(hasName("X")); }
getLangclang::ast_matchers::EnumConstant72   Language getLang() { return Lang_CXX; }
73 };
74 
75 struct Class {
76   using DeclTy = CXXRecordDecl;
77   static constexpr auto *Prototype = "class X;";
78   static constexpr auto *Definition = "class X {};";
79   static constexpr auto *ConflictingDefinition = "class X { int A; };";
getPatternclang::ast_matchers::Class80   BindableMatcher<Decl> getPattern() {
81     return cxxRecordDecl(hasName("X"), unless(isImplicit()));
82   }
getLangclang::ast_matchers::Class83   Language getLang() { return Lang_CXX; }
84 };
85 
86 struct Variable {
87   using DeclTy = VarDecl;
88   static constexpr auto *Prototype = "extern int X;";
89   static constexpr auto *ConflictingPrototype = "extern float X;";
90   static constexpr auto *Definition = "int X;";
91   static constexpr auto *ConflictingDefinition = "float X;";
getPatternclang::ast_matchers::Variable92   BindableMatcher<Decl> getPattern() { return varDecl(hasName("X")); }
getLangclang::ast_matchers::Variable93   Language getLang() { return Lang_CXX; }
94 };
95 
96 struct ClassTemplate {
97   using DeclTy = ClassTemplateDecl;
98   static constexpr auto *Prototype = "template <class> class X;";
99   static constexpr auto *ConflictingPrototype = "template <int> class X;";
100   static constexpr auto *Definition = "template <class> class X {};";
101   static constexpr auto *ConflictingDefinition =
102       "template <class> class X { int A; };";
103   static constexpr auto *ConflictingProtoDef = "template <int> class X { };";
getPatternclang::ast_matchers::ClassTemplate104   BindableMatcher<Decl> getPattern() {
105     return classTemplateDecl(hasName("X"), unless(isImplicit()));
106   }
getLangclang::ast_matchers::ClassTemplate107   Language getLang() { return Lang_CXX; }
108 };
109 
110 struct FunctionTemplate {
111   using DeclTy = FunctionTemplateDecl;
112   static constexpr auto *Definition0 =
113       R"(
114       template <class T>
115       void X(T a) {};
116       )";
117   // This is actually not a conflicting definition, but another primary template.
118   static constexpr auto *Definition1 =
119       R"(
120       template <class T>
121       void X(T* a) {};
122       )";
getPatternclang::ast_matchers::FunctionTemplate123   BindableMatcher<Decl> getPattern() {
124     return functionTemplateDecl(hasName("X"), unless(isImplicit()));
125   }
getDef0clang::ast_matchers::FunctionTemplate126   static std::string getDef0() { return Definition0; }
getDef1clang::ast_matchers::FunctionTemplate127   static std::string getDef1() { return Definition1; }
getLangclang::ast_matchers::FunctionTemplate128   Language getLang() { return Lang_CXX; }
129 };
130 
131 static const internal::VariadicDynCastAllOfMatcher<Decl, VarTemplateDecl>
132     varTemplateDecl;
133 
134 struct VarTemplate {
135   using DeclTy = VarTemplateDecl;
136   static constexpr auto *Definition =
137       R"(
138       template <class T>
139       constexpr T X = 0;
140       )";
141   static constexpr auto *ConflictingDefinition =
142       R"(
143       template <int>
144       constexpr int X = 0;
145       )";
getPatternclang::ast_matchers::VarTemplate146   BindableMatcher<Decl> getPattern() { return varTemplateDecl(hasName("X")); }
getLangclang::ast_matchers::VarTemplate147   Language getLang() { return Lang_CXX14; }
148 };
149 
150 struct ClassTemplateSpec {
151   using DeclTy = ClassTemplateSpecializationDecl;
152   static constexpr auto *Prototype =
153       R"(
154       template <class T> class X;
155       template <> class X<int>;
156       )";
157   static constexpr auto *Definition =
158       R"(
159       template <class T> class X;
160       template <> class X<int> {};
161       )";
162   static constexpr auto *ConflictingDefinition =
163       R"(
164       template <class T> class X;
165       template <> class X<int> { int A; };
166       )";
getPatternclang::ast_matchers::ClassTemplateSpec167   BindableMatcher<Decl> getPattern() {
168     return classTemplateSpecializationDecl(hasName("X"), unless(isImplicit()));
169   }
getLangclang::ast_matchers::ClassTemplateSpec170   Language getLang() { return Lang_CXX; }
171 };
172 
173 // Function template specializations are all "full" specializations.
174 // Structural equivalency does not check the body of functions, so we cannot
175 // create conflicting function template specializations.
176 struct FunctionTemplateSpec {
177   using DeclTy = FunctionDecl;
178 
179   static constexpr auto *Definition0 =
180       R"(
181       template <class T>
182       void X(T a);
183       template <> void X(int a) {};
184       )";
185 
186   // This is actually not a conflicting definition, but another full
187   // specialization.
188   // Thus, during the import we would create a new specialization with a
189   // different type argument.
190   static constexpr auto *Definition1 =
191       R"(
192       template <class T>
193       void X(T a);
194       template <> void X(double a) {};
195       )";
196 
getPatternclang::ast_matchers::FunctionTemplateSpec197   BindableMatcher<Decl> getPattern() {
198     return functionDecl(hasName("X"), isExplicitTemplateSpecialization(),
199                         unless(isImplicit()));
200   }
getDef0clang::ast_matchers::FunctionTemplateSpec201   static std::string getDef0() { return Definition0; }
getDef1clang::ast_matchers::FunctionTemplateSpec202   static std::string getDef1() { return Definition1; }
getLangclang::ast_matchers::FunctionTemplateSpec203   Language getLang() { return Lang_CXX; }
204 };
205 
206 static const internal::VariadicDynCastAllOfMatcher<
207     Decl, VarTemplateSpecializationDecl>
208     varTemplateSpecializationDecl;
209 
210 struct VarTemplateSpec {
211   using DeclTy = VarTemplateSpecializationDecl;
212   static constexpr auto *Definition =
213       R"(
214       template <class T> T X = 0;
215       template <> int X<int> = 0;
216       )";
217   static constexpr auto *ConflictingDefinition =
218       R"(
219       template <class T> T X = 0;
220       template <> float X<int> = 1.0;
221       )";
getPatternclang::ast_matchers::VarTemplateSpec222   BindableMatcher<Decl> getPattern() {
223     return varTemplateSpecializationDecl(hasName("X"), unless(isImplicit()));
224   }
getLangclang::ast_matchers::VarTemplateSpec225   Language getLang() { return Lang_CXX14; }
226 };
227 
228 template <typename TypeParam, ASTImporter::ODRHandlingType ODRHandlingParam>
229 struct ODRViolation : ASTImporterOptionSpecificTestBase {
230 
231   using DeclTy = typename TypeParam::DeclTy;
232 
ODRViolationclang::ast_matchers::ODRViolation233   ODRViolation() { ODRHandling = ODRHandlingParam; }
234 
getPrototypeclang::ast_matchers::ODRViolation235   static std::string getPrototype() { return TypeParam::Prototype; }
getConflictingPrototypeclang::ast_matchers::ODRViolation236   static std::string getConflictingPrototype() {
237     return TypeParam::ConflictingPrototype;
238   }
getDefinitionclang::ast_matchers::ODRViolation239   static std::string getDefinition() { return TypeParam::Definition; }
getConflictingDefinitionclang::ast_matchers::ODRViolation240   static std::string getConflictingDefinition() {
241     return TypeParam::ConflictingDefinition;
242   }
getConflictingProtoDefclang::ast_matchers::ODRViolation243   static std::string getConflictingProtoDef() {
244     return TypeParam::ConflictingProtoDef;
245   }
getPatternclang::ast_matchers::ODRViolation246   static BindableMatcher<Decl> getPattern() { return TypeParam().getPattern(); }
getLangclang::ast_matchers::ODRViolation247   static Language getLang() { return TypeParam().getLang(); }
248 
249   template <std::string (*ToTUContent)(), std::string (*FromTUContent)(),
250             void (*ResultChecker)(llvm::Expected<Decl *> &, Decl *, Decl *)>
TypedTest_ImportAfterclang::ast_matchers::ODRViolation251   void TypedTest_ImportAfter() {
252     Decl *ToTU = getToTuDecl(ToTUContent(), getLang());
253     auto *ToD = FirstDeclMatcher<DeclTy>().match(ToTU, getPattern());
254 
255     Decl *FromTU = getTuDecl(FromTUContent(), getLang());
256     auto *FromD = FirstDeclMatcher<DeclTy>().match(FromTU, getPattern());
257 
258     auto Result = importOrError(FromD, getLang());
259 
260     ResultChecker(Result, ToTU, ToD);
261   }
262 
263   // Check that a Decl has been successfully imported into a standalone redecl
264   // chain.
CheckImportedAsNewclang::ast_matchers::ODRViolation265   static void CheckImportedAsNew(llvm::Expected<Decl *> &Result, Decl *ToTU,
266                                  Decl *ToD) {
267     ASSERT_TRUE(isSuccess(Result));
268     Decl *ImportedD = *Result;
269     ASSERT_TRUE(ImportedD);
270     EXPECT_NE(ImportedD, ToD);
271     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 2u);
272 
273     // There may be a hidden fwd spec decl before a function spec decl.
274     if (auto *ImportedF = dyn_cast<FunctionDecl>(ImportedD))
275       if (ImportedF->getTemplatedKind() ==
276           FunctionDecl::TK_FunctionTemplateSpecialization)
277         return;
278 
279     EXPECT_FALSE(ImportedD->getPreviousDecl());
280   }
281 
282   // Check that a Decl was not imported because of NameConflict.
CheckImportNameConflictclang::ast_matchers::ODRViolation283   static void CheckImportNameConflict(llvm::Expected<Decl *> &Result,
284                                       Decl *ToTU, Decl *ToD) {
285     EXPECT_TRUE(isImportError(Result, ImportError::NameConflict));
286     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 1u);
287   }
288 
289   // Check that a Decl was not imported because lookup found the same decl.
CheckImportFoundExistingclang::ast_matchers::ODRViolation290   static void CheckImportFoundExisting(llvm::Expected<Decl *> &Result,
291                                       Decl *ToTU, Decl *ToD) {
292     ASSERT_TRUE(isSuccess(Result));
293     EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 1u);
294   }
295 
TypedTest_ImportConflictingDefAfterDefclang::ast_matchers::ODRViolation296   void TypedTest_ImportConflictingDefAfterDef() {
297     TypedTest_ImportAfter<getDefinition, getConflictingDefinition,
298                           CheckImportedAsNew>();
299   }
TypedTest_ImportConflictingProtoAfterProtoclang::ast_matchers::ODRViolation300   void TypedTest_ImportConflictingProtoAfterProto() {
301     TypedTest_ImportAfter<getPrototype, getConflictingPrototype,
302                           CheckImportedAsNew>();
303   }
TypedTest_ImportConflictingProtoAfterDefclang::ast_matchers::ODRViolation304   void TypedTest_ImportConflictingProtoAfterDef() {
305     TypedTest_ImportAfter<getDefinition, getConflictingPrototype,
306                           CheckImportedAsNew>();
307   }
TypedTest_ImportConflictingDefAfterProtoclang::ast_matchers::ODRViolation308   void TypedTest_ImportConflictingDefAfterProto() {
309     TypedTest_ImportAfter<getConflictingPrototype, getDefinition,
310                           CheckImportedAsNew>();
311   }
TypedTest_ImportConflictingProtoDefAfterProtoclang::ast_matchers::ODRViolation312   void TypedTest_ImportConflictingProtoDefAfterProto() {
313     TypedTest_ImportAfter<getPrototype, getConflictingProtoDef,
314                           CheckImportedAsNew>();
315   }
TypedTest_ImportConflictingProtoAfterProtoDefclang::ast_matchers::ODRViolation316   void TypedTest_ImportConflictingProtoAfterProtoDef() {
317     TypedTest_ImportAfter<getConflictingProtoDef, getPrototype,
318                           CheckImportedAsNew>();
319   }
TypedTest_ImportConflictingProtoDefAfterDefclang::ast_matchers::ODRViolation320   void TypedTest_ImportConflictingProtoDefAfterDef() {
321     TypedTest_ImportAfter<getDefinition, getConflictingProtoDef,
322                           CheckImportedAsNew>();
323   }
TypedTest_ImportConflictingDefAfterProtoDefclang::ast_matchers::ODRViolation324   void TypedTest_ImportConflictingDefAfterProtoDef() {
325     TypedTest_ImportAfter<getConflictingProtoDef, getDefinition,
326                           CheckImportedAsNew>();
327   }
328 
TypedTest_DontImportConflictingProtoAfterProtoclang::ast_matchers::ODRViolation329   void TypedTest_DontImportConflictingProtoAfterProto() {
330     TypedTest_ImportAfter<getPrototype, getConflictingPrototype,
331                           CheckImportNameConflict>();
332   }
TypedTest_DontImportConflictingDefAfterDefclang::ast_matchers::ODRViolation333   void TypedTest_DontImportConflictingDefAfterDef() {
334     TypedTest_ImportAfter<getDefinition, getConflictingDefinition,
335                           CheckImportNameConflict>();
336   }
TypedTest_DontImportConflictingProtoAfterDefclang::ast_matchers::ODRViolation337   void TypedTest_DontImportConflictingProtoAfterDef() {
338     TypedTest_ImportAfter<getDefinition, getConflictingPrototype,
339                           CheckImportNameConflict>();
340   }
TypedTest_DontImportConflictingDefAfterProtoclang::ast_matchers::ODRViolation341   void TypedTest_DontImportConflictingDefAfterProto() {
342     TypedTest_ImportAfter<getConflictingPrototype, getDefinition,
343                           CheckImportNameConflict>();
344   }
TypedTest_DontImportConflictingProtoDefAfterProtoclang::ast_matchers::ODRViolation345   void TypedTest_DontImportConflictingProtoDefAfterProto() {
346     TypedTest_ImportAfter<getPrototype, getConflictingProtoDef,
347                           CheckImportNameConflict>();
348   }
TypedTest_DontImportConflictingProtoAfterProtoDefclang::ast_matchers::ODRViolation349   void TypedTest_DontImportConflictingProtoAfterProtoDef() {
350     TypedTest_ImportAfter<getConflictingProtoDef, getPrototype,
351                           CheckImportNameConflict>();
352   }
TypedTest_DontImportConflictingProtoDefAfterDefclang::ast_matchers::ODRViolation353   void TypedTest_DontImportConflictingProtoDefAfterDef() {
354     TypedTest_ImportAfter<getDefinition, getConflictingProtoDef,
355                           CheckImportNameConflict>();
356   }
TypedTest_DontImportConflictingDefAfterProtoDefclang::ast_matchers::ODRViolation357   void TypedTest_DontImportConflictingDefAfterProtoDef() {
358     TypedTest_ImportAfter<getConflictingProtoDef, getDefinition,
359                           CheckImportNameConflict>();
360   }
361 
362   // Used for function templates and function template specializations.
TypedTest_ImportDifferentDefAfterDefclang::ast_matchers::ODRViolation363   void TypedTest_ImportDifferentDefAfterDef() {
364     TypedTest_ImportAfter<TypeParam::getDef0, TypeParam::getDef1,
365                           CheckImportedAsNew>();
366   }
TypedTest_DontImportSameDefAfterDefclang::ast_matchers::ODRViolation367   void TypedTest_DontImportSameDefAfterDef() {
368     TypedTest_ImportAfter<TypeParam::getDef0, TypeParam::getDef0,
369                           CheckImportFoundExisting>();
370   }
371 };
372 
373 // ==============================
374 // Define the parametrized tests.
375 // ==============================
376 
377 #define ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(                           \
378     TypeParam, ODRHandlingParam, NamePrefix, TestCase)                         \
379   using TypeParam##ODRHandlingParam =                                          \
380       ODRViolation<TypeParam, ASTImporter::ODRHandlingType::ODRHandlingParam>; \
381   TEST_P(TypeParam##ODRHandlingParam, NamePrefix##TestCase) {                  \
382     TypedTest_##TestCase();                                                    \
383   }
384 
385 // clang-format off
386 
387 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
388     Function, Liberal, ,
389     ImportConflictingDefAfterDef)
390 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
391     Typedef, Liberal, ,
392     ImportConflictingDefAfterDef)
393 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
394     TypedefAlias, Liberal, ,
395     ImportConflictingDefAfterDef)
396 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
397     Enum, Liberal, ,
398     ImportConflictingDefAfterDef)
399 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
400     EnumConstant, Liberal, ,
401     ImportConflictingDefAfterDef)
402 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
403     Class, Liberal, ,
404     ImportConflictingDefAfterDef)
405 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
406     Variable, Liberal, ,
407     ImportConflictingDefAfterDef)
408 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
409     ClassTemplate, Liberal, ,
410     ImportConflictingDefAfterDef)
411 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
412     VarTemplate, Liberal, ,
413     ImportConflictingDefAfterDef)
414 // Class and variable template specializations/instantiatons are always
415 // imported conservatively, because the AST holds the specializations in a set,
416 // and the key within the set is a hash calculated from the arguments of the
417 // specialization.
418 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
419     ClassTemplateSpec, Liberal, ,
420     DontImportConflictingDefAfterDef) // Don't import !!!
421 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
422     VarTemplateSpec, Liberal, ,
423     DontImportConflictingDefAfterDef) // Don't import !!!
424 
425 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
426     Function, Conservative, ,
427     DontImportConflictingDefAfterDef)
428 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
429     Typedef, Conservative, ,
430     DontImportConflictingDefAfterDef)
431 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
432     TypedefAlias, Conservative, ,
433     DontImportConflictingDefAfterDef)
434 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
435     Enum, Conservative, ,
436     DontImportConflictingDefAfterDef)
437 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
438     EnumConstant, Conservative, ,
439     DontImportConflictingDefAfterDef)
440 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
441     Class, Conservative, ,
442     DontImportConflictingDefAfterDef)
443 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
444     Variable, Conservative, ,
445     DontImportConflictingDefAfterDef)
446 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
447     ClassTemplate, Conservative, ,
448     DontImportConflictingDefAfterDef)
449 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
450     VarTemplate, Conservative, ,
451     DontImportConflictingDefAfterDef)
452 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
453     ClassTemplateSpec, Conservative, ,
454     DontImportConflictingDefAfterDef)
455 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
456     VarTemplateSpec, Conservative, ,
457     DontImportConflictingDefAfterDef)
458 
459 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
460     Function, Liberal, ,
461     ImportConflictingProtoAfterProto)
462 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
463     Variable, Liberal, ,
464     ImportConflictingProtoAfterProto)
465 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
466     ClassTemplate, Liberal, ,
467     ImportConflictingProtoAfterProto)
468 
469 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
470     Function, Conservative, ,
471     DontImportConflictingProtoAfterProto)
472 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
473     Variable, Conservative, ,
474     DontImportConflictingProtoAfterProto)
475 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
476     ClassTemplate, Conservative, ,
477     DontImportConflictingProtoAfterProto)
478 
479 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
480     Variable, Liberal, ,
481     ImportConflictingProtoAfterDef)
482 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
483     ClassTemplate, Liberal, ,
484     ImportConflictingProtoAfterDef)
485 
486 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
487     Variable, Conservative, ,
488     DontImportConflictingProtoAfterDef)
489 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
490     ClassTemplate, Conservative, ,
491     DontImportConflictingProtoAfterDef)
492 
493 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
494     Function, Liberal, ,
495     ImportConflictingDefAfterProto)
496 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
497     Variable, Liberal, ,
498     ImportConflictingDefAfterProto)
499 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
500     ClassTemplate, Liberal, ,
501     ImportConflictingDefAfterProto)
502 
503 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
504     Function, Conservative, ,
505     DontImportConflictingDefAfterProto)
506 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
507     Variable, Conservative, ,
508     DontImportConflictingDefAfterProto)
509 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
510     ClassTemplate, Conservative, ,
511     DontImportConflictingDefAfterProto)
512 
513 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
514     ClassTemplate, Liberal, ,
515     ImportConflictingProtoDefAfterProto)
516 
517 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
518     ClassTemplate, Conservative, ,
519     DontImportConflictingProtoDefAfterProto)
520 
521 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
522     ClassTemplate, Liberal, ,
523     ImportConflictingProtoAfterProtoDef)
524 
525 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
526     ClassTemplate, Conservative, ,
527     DontImportConflictingProtoAfterProtoDef)
528 
529 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
530     ClassTemplate, Liberal, ,
531     ImportConflictingProtoDefAfterDef)
532 
533 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
534     ClassTemplate, Conservative, ,
535     DontImportConflictingProtoDefAfterDef)
536 
537 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
538     ClassTemplate, Liberal, ,
539     ImportConflictingDefAfterProtoDef)
540 
541 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
542     ClassTemplate, Conservative, ,
543     DontImportConflictingDefAfterProtoDef)
544 
545 // FunctionTemplate decls overload with each other. Thus, they are imported
546 // always as a new node, independently from any ODRHandling strategy.
547 //
548 // Function template specializations are "full" specializations. Structural
549 // equivalency does not check the body of functions, so we cannot create
550 // conflicting function template specializations. Thus, ODR handling strategies
551 // has nothing to do with function template specializations. Fully specialized
552 // function templates are imported as new nodes if their template arguments are
553 // different.
554 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
555     FunctionTemplate, Liberal, ,
556     ImportDifferentDefAfterDef)
557 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
558     FunctionTemplateSpec, Liberal, ,
559     ImportDifferentDefAfterDef)
560 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
561     FunctionTemplate, Conservative, ,
562     ImportDifferentDefAfterDef)
563 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
564     FunctionTemplateSpec, Conservative, ,
565     ImportDifferentDefAfterDef)
566 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
567     FunctionTemplate, Liberal, ,
568     DontImportSameDefAfterDef)
569 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
570     FunctionTemplateSpec, Liberal, ,
571     DontImportSameDefAfterDef)
572 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
573     FunctionTemplate, Conservative, ,
574     DontImportSameDefAfterDef)
575 ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_CASE(
576     FunctionTemplateSpec, Conservative, ,
577     DontImportSameDefAfterDef)
578 
579 // ======================
580 // Instantiate the tests.
581 // ======================
582 
583 // FIXME: These fail on Windows.
584 #if !defined(_WIN32)
585 INSTANTIATE_TEST_CASE_P(
586     ODRViolationTests, FunctionConservative,
587     DefaultTestValuesForRunOptions, );
588 #endif
589 INSTANTIATE_TEST_CASE_P(
590     ODRViolationTests, TypedefConservative,
591     DefaultTestValuesForRunOptions, );
592 INSTANTIATE_TEST_CASE_P(
593     ODRViolationTests, TypedefAliasConservative,
594     DefaultTestValuesForRunOptions, );
595 INSTANTIATE_TEST_CASE_P(
596     ODRViolationTests, EnumConservative,
597     DefaultTestValuesForRunOptions, );
598 INSTANTIATE_TEST_CASE_P(
599     ODRViolationTests, EnumConstantConservative,
600     DefaultTestValuesForRunOptions, );
601 INSTANTIATE_TEST_CASE_P(
602     ODRViolationTests, ClassConservative,
603     DefaultTestValuesForRunOptions, );
604 INSTANTIATE_TEST_CASE_P(
605     ODRViolationTests, VariableConservative,
606     DefaultTestValuesForRunOptions, );
607 INSTANTIATE_TEST_CASE_P(
608     ODRViolationTests, ClassTemplateConservative,
609     DefaultTestValuesForRunOptions, );
610 INSTANTIATE_TEST_CASE_P(
611     ODRViolationTests, FunctionTemplateConservative,
612     DefaultTestValuesForRunOptions, );
613 // FIXME: Make VarTemplate tests work.
614 //INSTANTIATE_TEST_CASE_P(
615     //ODRViolationTests, VarTemplateConservative,
616     //DefaultTestValuesForRunOptions, );
617 INSTANTIATE_TEST_CASE_P(
618     ODRViolationTests, FunctionTemplateSpecConservative,
619     DefaultTestValuesForRunOptions, );
620 INSTANTIATE_TEST_CASE_P(
621     ODRViolationTests, ClassTemplateSpecConservative,
622     DefaultTestValuesForRunOptions, );
623 // FIXME: Make VarTemplateSpec tests work.
624 //INSTANTIATE_TEST_CASE_P(
625     //ODRViolationTests, VarTemplateSpecConservative,
626     //DefaultTestValuesForRunOptions, );
627 
628 // FIXME: These fail on Windows.
629 #if !defined(_WIN32)
630 INSTANTIATE_TEST_CASE_P(
631     ODRViolationTests, FunctionLiberal,
632     DefaultTestValuesForRunOptions, );
633 #endif
634 INSTANTIATE_TEST_CASE_P(
635     ODRViolationTests, TypedefLiberal,
636     DefaultTestValuesForRunOptions, );
637 INSTANTIATE_TEST_CASE_P(
638     ODRViolationTests, TypedefAliasLiberal,
639     DefaultTestValuesForRunOptions, );
640 INSTANTIATE_TEST_CASE_P(
641     ODRViolationTests, EnumLiberal,
642     DefaultTestValuesForRunOptions, );
643 INSTANTIATE_TEST_CASE_P(
644     ODRViolationTests, EnumConstantLiberal,
645     DefaultTestValuesForRunOptions, );
646 INSTANTIATE_TEST_CASE_P(
647     ODRViolationTests, ClassLiberal,
648     DefaultTestValuesForRunOptions, );
649 INSTANTIATE_TEST_CASE_P(
650     ODRViolationTests, VariableLiberal,
651     DefaultTestValuesForRunOptions, );
652 INSTANTIATE_TEST_CASE_P(
653     ODRViolationTests, ClassTemplateLiberal,
654     DefaultTestValuesForRunOptions, );
655 INSTANTIATE_TEST_CASE_P(
656     ODRViolationTests, FunctionTemplateLiberal,
657     DefaultTestValuesForRunOptions, );
658 // FIXME: Make VarTemplate tests work.
659 // INSTANTIATE_TEST_CASE_P(
660 //     ODRViolationTests, VarTemplateLiberal,
661 //     DefaultTestValuesForRunOptions, );
662 INSTANTIATE_TEST_CASE_P(
663     ODRViolationTests, ClassTemplateSpecLiberal,
664     DefaultTestValuesForRunOptions, );
665 INSTANTIATE_TEST_CASE_P(
666     ODRViolationTests, FunctionTemplateSpecLiberal,
667     DefaultTestValuesForRunOptions, );
668 // FIXME: Make VarTemplateSpec tests work.
669 //INSTANTIATE_TEST_CASE_P(
670     //ODRViolationTests, VarTemplateSpecLiberal,
671     //DefaultTestValuesForRunOptions, );
672 
673 // clang-format on
674 
675 } // end namespace ast_matchers
676 } // end namespace clang
677