1//===- 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
16namespace clang {
17namespace ast_matchers {
18
19using 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
31struct 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) {}";
37 BindableMatcher<Decl> getPattern() {
38 return functionDecl(hasName(Name: "X"), unless(isImplicit()));
39 }
40 TestLanguage getLang() { return Lang_C99; }
41};
42
43struct Typedef {
44 using DeclTy = TypedefNameDecl;
45 static constexpr auto *Definition = "typedef int X;";
46 static constexpr auto *ConflictingDefinition = "typedef double X;";
47 BindableMatcher<Decl> getPattern() { return typedefNameDecl(hasName(Name: "X")); }
48 TestLanguage getLang() { return Lang_CXX03; }
49};
50
51struct TypedefAlias {
52 using DeclTy = TypedefNameDecl;
53 static constexpr auto *Definition = "using X = int;";
54 static constexpr auto *ConflictingDefinition = "using X = double;";
55 BindableMatcher<Decl> getPattern() { return typedefNameDecl(hasName(Name: "X")); }
56 TestLanguage getLang() { return Lang_CXX11; }
57};
58
59struct Enum {
60 using DeclTy = EnumDecl;
61 static constexpr auto *Definition = "enum X { a, b };";
62 static constexpr auto *ConflictingDefinition = "enum X { a, b, c };";
63 BindableMatcher<Decl> getPattern() { return enumDecl(hasName(Name: "X")); }
64 TestLanguage getLang() { return Lang_CXX03; }
65};
66
67struct EnumClass {
68 using DeclTy = EnumDecl;
69 static constexpr auto *Definition = "enum class X { a, b };";
70 static constexpr auto *ConflictingDefinition = "enum class X { a, b, c };";
71 BindableMatcher<Decl> getPattern() { return enumDecl(hasName(Name: "X")); }
72 TestLanguage getLang() { return Lang_CXX11; }
73};
74
75struct EnumConstant {
76 using DeclTy = EnumConstantDecl;
77 static constexpr auto *Definition = "enum E { X = 0 };";
78 static constexpr auto *ConflictingDefinition = "enum E { X = 1 };";
79 BindableMatcher<Decl> getPattern() { return enumConstantDecl(hasName(Name: "X")); }
80 TestLanguage getLang() { return Lang_CXX03; }
81};
82
83struct Class {
84 using DeclTy = CXXRecordDecl;
85 static constexpr auto *Prototype = "class X;";
86 static constexpr auto *Definition = "class X {};";
87 static constexpr auto *ConflictingDefinition = "class X { int A; };";
88 BindableMatcher<Decl> getPattern() {
89 return cxxRecordDecl(hasName(Name: "X"), unless(isImplicit()));
90 }
91 TestLanguage getLang() { return Lang_CXX03; }
92};
93
94struct Variable {
95 using DeclTy = VarDecl;
96 static constexpr auto *Prototype = "extern int X;";
97 static constexpr auto *ConflictingPrototype = "extern float X;";
98 static constexpr auto *Definition = "int X;";
99 static constexpr auto *ConflictingDefinition = "float X;";
100 BindableMatcher<Decl> getPattern() { return varDecl(hasName(Name: "X")); }
101 TestLanguage getLang() { return Lang_CXX03; }
102};
103
104struct ClassTemplate {
105 using DeclTy = ClassTemplateDecl;
106 static constexpr auto *Prototype = "template <class> class X;";
107 static constexpr auto *ConflictingPrototype = "template <int> class X;";
108 static constexpr auto *Definition = "template <class> class X {};";
109 static constexpr auto *ConflictingDefinition =
110 "template <class> class X { int A; };";
111 static constexpr auto *ConflictingProtoDef = "template <int> class X { };";
112 BindableMatcher<Decl> getPattern() {
113 return classTemplateDecl(hasName(Name: "X"), unless(isImplicit()));
114 }
115 TestLanguage getLang() { return Lang_CXX03; }
116};
117
118struct FunctionTemplate {
119 using DeclTy = FunctionTemplateDecl;
120 static constexpr auto *Definition0 =
121 R"(
122 template <class T>
123 void X(T a) {};
124 )";
125 // This is actually not a conflicting definition, but another primary template.
126 static constexpr auto *Definition1 =
127 R"(
128 template <class T>
129 void X(T* a) {};
130 )";
131 BindableMatcher<Decl> getPattern() {
132 return functionTemplateDecl(hasName(Name: "X"), unless(isImplicit()));
133 }
134 static std::string getDef0() { return Definition0; }
135 static std::string getDef1() { return Definition1; }
136 TestLanguage getLang() { return Lang_CXX03; }
137};
138
139static const internal::VariadicDynCastAllOfMatcher<Decl, VarTemplateDecl>
140 varTemplateDecl;
141
142struct VarTemplate {
143 using DeclTy = VarTemplateDecl;
144 static constexpr auto *Definition =
145 R"(
146 template <class T>
147 constexpr T X = 0;
148 )";
149 static constexpr auto *ConflictingDefinition =
150 R"(
151 template <int>
152 constexpr int X = 0;
153 )";
154 BindableMatcher<Decl> getPattern() { return varTemplateDecl(hasName(Name: "X")); }
155 TestLanguage getLang() { return Lang_CXX14; }
156};
157
158struct ClassTemplateSpec {
159 using DeclTy = ClassTemplateSpecializationDecl;
160 static constexpr auto *Prototype =
161 R"(
162 template <class T> class X;
163 template <> class X<int>;
164 )";
165 static constexpr auto *Definition =
166 R"(
167 template <class T> class X;
168 template <> class X<int> {};
169 )";
170 static constexpr auto *ConflictingDefinition =
171 R"(
172 template <class T> class X;
173 template <> class X<int> { int A; };
174 )";
175 BindableMatcher<Decl> getPattern() {
176 return classTemplateSpecializationDecl(hasName(Name: "X"), unless(isImplicit()));
177 }
178 TestLanguage getLang() { return Lang_CXX03; }
179};
180
181// Function template specializations are all "full" specializations.
182// Structural equivalency does not check the body of functions, so we cannot
183// create conflicting function template specializations.
184struct FunctionTemplateSpec {
185 using DeclTy = FunctionDecl;
186
187 static constexpr auto *Definition0 =
188 R"(
189 template <class T>
190 void X(T a);
191 template <> void X(int a) {};
192 )";
193
194 // This is actually not a conflicting definition, but another full
195 // specialization.
196 // Thus, during the import we would create a new specialization with a
197 // different type argument.
198 static constexpr auto *Definition1 =
199 R"(
200 template <class T>
201 void X(T a);
202 template <> void X(double a) {};
203 )";
204
205 BindableMatcher<Decl> getPattern() {
206 return functionDecl(hasName(Name: "X"), isExplicitTemplateSpecialization(),
207 unless(isImplicit()));
208 }
209 static std::string getDef0() { return Definition0; }
210 static std::string getDef1() { return Definition1; }
211 TestLanguage getLang() { return Lang_CXX03; }
212};
213
214static const internal::VariadicDynCastAllOfMatcher<
215 Decl, VarTemplateSpecializationDecl>
216 varTemplateSpecializationDecl;
217
218struct VarTemplateSpec {
219 using DeclTy = VarTemplateSpecializationDecl;
220 static constexpr auto *Definition =
221 R"(
222 template <class T> T X = 0;
223 template <> int X<int> = 0;
224 )";
225 static constexpr auto *ConflictingDefinition =
226 R"(
227 template <class T> T X = 0;
228 template <> float X<int> = 1.0;
229 )";
230 BindableMatcher<Decl> getPattern() {
231 return varTemplateSpecializationDecl(hasName(Name: "X"), unless(isImplicit()));
232 }
233 TestLanguage getLang() { return Lang_CXX14; }
234};
235
236template <typename TypeParam, ASTImporter::ODRHandlingType ODRHandlingParam>
237struct ODRViolation : ASTImporterOptionSpecificTestBase {
238
239 using DeclTy = typename TypeParam::DeclTy;
240
241 ODRViolation() { ODRHandling = ODRHandlingParam; }
242
243 static std::string getPrototype() { return TypeParam::Prototype; }
244 static std::string getConflictingPrototype() {
245 return TypeParam::ConflictingPrototype;
246 }
247 static std::string getDefinition() { return TypeParam::Definition; }
248 static std::string getConflictingDefinition() {
249 return TypeParam::ConflictingDefinition;
250 }
251 static std::string getConflictingProtoDef() {
252 return TypeParam::ConflictingProtoDef;
253 }
254 static BindableMatcher<Decl> getPattern() { return TypeParam().getPattern(); }
255 static TestLanguage getLang() { return TypeParam().getLang(); }
256
257 template <std::string (*ToTUContent)(), std::string (*FromTUContent)(),
258 void (*ResultChecker)(llvm::Expected<Decl *> &, Decl *, Decl *)>
259 void TypedTest_ImportAfter() {
260 Decl *ToTU = getToTuDecl(ToSrcCode: ToTUContent(), ToLang: getLang());
261 auto *ToD = FirstDeclMatcher<DeclTy>().match(ToTU, getPattern());
262
263 Decl *FromTU = getTuDecl(SrcCode: FromTUContent(), Lang: getLang());
264 auto *FromD = FirstDeclMatcher<DeclTy>().match(FromTU, getPattern());
265
266 auto Result = importOrError(From: FromD, ToLang: getLang());
267
268 ResultChecker(Result, ToTU, ToD);
269 }
270
271 // Check that a Decl has been successfully imported into a standalone redecl
272 // chain.
273 static void CheckImportedAsNew(llvm::Expected<Decl *> &Result, Decl *ToTU,
274 Decl *ToD) {
275 ASSERT_TRUE(isSuccess(Result));
276 Decl *ImportedD = *Result;
277 ASSERT_TRUE(ImportedD);
278 EXPECT_NE(ImportedD, ToD);
279 EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 2u);
280
281 // There may be a hidden fwd spec decl before a function spec decl.
282 if (auto *ImportedF = dyn_cast<FunctionDecl>(Val: ImportedD))
283 if (ImportedF->getTemplatedKind() ==
284 FunctionDecl::TK_FunctionTemplateSpecialization)
285 return;
286
287 EXPECT_FALSE(ImportedD->getPreviousDecl());
288 }
289
290 // Check that a Decl was not imported because of NameConflict.
291 static void CheckImportNameConflict(llvm::Expected<Decl *> &Result,
292 Decl *ToTU, Decl *ToD) {
293 EXPECT_TRUE(isImportError(Result, ASTImportError::NameConflict));
294 EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 1u);
295 }
296
297 // Check that a Decl was not imported because lookup found the same decl.
298 static void CheckImportFoundExisting(llvm::Expected<Decl *> &Result,
299 Decl *ToTU, Decl *ToD) {
300 ASSERT_TRUE(isSuccess(Result));
301 EXPECT_EQ(DeclCounter<DeclTy>().match(ToTU, getPattern()), 1u);
302 }
303
304 void TypedTest_ImportConflictingDefAfterDef() {
305 TypedTest_ImportAfter<getDefinition, getConflictingDefinition,
306 CheckImportedAsNew>();
307 }
308 void TypedTest_ImportConflictingProtoAfterProto() {
309 TypedTest_ImportAfter<getPrototype, getConflictingPrototype,
310 CheckImportedAsNew>();
311 }
312 void TypedTest_ImportConflictingProtoAfterDef() {
313 TypedTest_ImportAfter<getDefinition, getConflictingPrototype,
314 CheckImportedAsNew>();
315 }
316 void TypedTest_ImportConflictingDefAfterProto() {
317 TypedTest_ImportAfter<getConflictingPrototype, getDefinition,
318 CheckImportedAsNew>();
319 }
320 void TypedTest_ImportConflictingProtoDefAfterProto() {
321 TypedTest_ImportAfter<getPrototype, getConflictingProtoDef,
322 CheckImportedAsNew>();
323 }
324 void TypedTest_ImportConflictingProtoAfterProtoDef() {
325 TypedTest_ImportAfter<getConflictingProtoDef, getPrototype,
326 CheckImportedAsNew>();
327 }
328 void TypedTest_ImportConflictingProtoDefAfterDef() {
329 TypedTest_ImportAfter<getDefinition, getConflictingProtoDef,
330 CheckImportedAsNew>();
331 }
332 void TypedTest_ImportConflictingDefAfterProtoDef() {
333 TypedTest_ImportAfter<getConflictingProtoDef, getDefinition,
334 CheckImportedAsNew>();
335 }
336
337 void TypedTest_DontImportConflictingProtoAfterProto() {
338 TypedTest_ImportAfter<getPrototype, getConflictingPrototype,
339 CheckImportNameConflict>();
340 }
341 void TypedTest_DontImportConflictingDefAfterDef() {
342 TypedTest_ImportAfter<getDefinition, getConflictingDefinition,
343 CheckImportNameConflict>();
344 }
345 void TypedTest_DontImportConflictingProtoAfterDef() {
346 TypedTest_ImportAfter<getDefinition, getConflictingPrototype,
347 CheckImportNameConflict>();
348 }
349 void TypedTest_DontImportConflictingDefAfterProto() {
350 TypedTest_ImportAfter<getConflictingPrototype, getDefinition,
351 CheckImportNameConflict>();
352 }
353 void TypedTest_DontImportConflictingProtoDefAfterProto() {
354 TypedTest_ImportAfter<getPrototype, getConflictingProtoDef,
355 CheckImportNameConflict>();
356 }
357 void TypedTest_DontImportConflictingProtoAfterProtoDef() {
358 TypedTest_ImportAfter<getConflictingProtoDef, getPrototype,
359 CheckImportNameConflict>();
360 }
361 void TypedTest_DontImportConflictingProtoDefAfterDef() {
362 TypedTest_ImportAfter<getDefinition, getConflictingProtoDef,
363 CheckImportNameConflict>();
364 }
365 void TypedTest_DontImportConflictingDefAfterProtoDef() {
366 TypedTest_ImportAfter<getConflictingProtoDef, getDefinition,
367 CheckImportNameConflict>();
368 }
369
370 // Used for function templates and function template specializations.
371 void TypedTest_ImportDifferentDefAfterDef() {
372 TypedTest_ImportAfter<TypeParam::getDef0, TypeParam::getDef1,
373 CheckImportedAsNew>();
374 }
375 void TypedTest_DontImportSameDefAfterDef() {
376 TypedTest_ImportAfter<TypeParam::getDef0, TypeParam::getDef0,
377 CheckImportFoundExisting>();
378 }
379};
380
381// ==============================
382// Define the parametrized tests.
383// ==============================
384
385#define ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE( \
386 TypeParam, ODRHandlingParam, NamePrefix, TestCase) \
387 using TypeParam##ODRHandlingParam = \
388 ODRViolation<TypeParam, ASTImporter::ODRHandlingType::ODRHandlingParam>; \
389 TEST_P(TypeParam##ODRHandlingParam, NamePrefix##TestCase) { \
390 TypedTest_##TestCase(); \
391 }
392
393// clang-format off
394
395ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
396 Function, Liberal, ,
397 ImportConflictingDefAfterDef)
398ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
399 Typedef, Liberal, ,
400 ImportConflictingDefAfterDef)
401ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
402 TypedefAlias, Liberal, ,
403 ImportConflictingDefAfterDef)
404ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
405 Enum, Liberal, ,
406 ImportConflictingDefAfterDef)
407ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
408 EnumClass, Liberal, ,
409 ImportConflictingDefAfterDef)
410ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
411 EnumConstant, Liberal, ,
412 ImportConflictingDefAfterDef)
413ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
414 Class, Liberal, ,
415 ImportConflictingDefAfterDef)
416ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
417 Variable, Liberal, ,
418 ImportConflictingDefAfterDef)
419ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
420 ClassTemplate, Liberal, ,
421 ImportConflictingDefAfterDef)
422ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
423 VarTemplate, Liberal, ,
424 ImportConflictingDefAfterDef)
425// Class and variable template specializations/instantiatons are always
426// imported conservatively, because the AST holds the specializations in a set,
427// and the key within the set is a hash calculated from the arguments of the
428// specialization.
429ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
430 ClassTemplateSpec, Liberal, ,
431 DontImportConflictingDefAfterDef) // Don't import !!!
432ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
433 VarTemplateSpec, Liberal, ,
434 DontImportConflictingDefAfterDef) // Don't import !!!
435
436ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
437 Function, Conservative, ,
438 DontImportConflictingDefAfterDef)
439ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
440 Typedef, Conservative, ,
441 DontImportConflictingDefAfterDef)
442ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
443 TypedefAlias, Conservative, ,
444 DontImportConflictingDefAfterDef)
445ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
446 Enum, Conservative, ,
447 DontImportConflictingDefAfterDef)
448ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
449 EnumClass, Conservative, ,
450 DontImportConflictingDefAfterDef)
451ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
452 EnumConstant, Conservative, ,
453 DontImportConflictingDefAfterDef)
454ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
455 Class, Conservative, ,
456 DontImportConflictingDefAfterDef)
457ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
458 Variable, Conservative, ,
459 DontImportConflictingDefAfterDef)
460ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
461 ClassTemplate, Conservative, ,
462 DontImportConflictingDefAfterDef)
463ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
464 VarTemplate, Conservative, ,
465 DontImportConflictingDefAfterDef)
466ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
467 ClassTemplateSpec, Conservative, ,
468 DontImportConflictingDefAfterDef)
469ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
470 VarTemplateSpec, Conservative, ,
471 DontImportConflictingDefAfterDef)
472
473ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
474 Function, Liberal, ,
475 ImportConflictingProtoAfterProto)
476ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
477 Variable, Liberal, ,
478 ImportConflictingProtoAfterProto)
479ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
480 ClassTemplate, Liberal, ,
481 ImportConflictingProtoAfterProto)
482
483ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
484 Function, Conservative, ,
485 DontImportConflictingProtoAfterProto)
486ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
487 Variable, Conservative, ,
488 DontImportConflictingProtoAfterProto)
489ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
490 ClassTemplate, Conservative, ,
491 DontImportConflictingProtoAfterProto)
492
493ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
494 Variable, Liberal, ,
495 ImportConflictingProtoAfterDef)
496ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
497 ClassTemplate, Liberal, ,
498 ImportConflictingProtoAfterDef)
499
500ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
501 Variable, Conservative, ,
502 DontImportConflictingProtoAfterDef)
503ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
504 ClassTemplate, Conservative, ,
505 DontImportConflictingProtoAfterDef)
506
507ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
508 Function, Liberal, ,
509 ImportConflictingDefAfterProto)
510ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
511 Variable, Liberal, ,
512 ImportConflictingDefAfterProto)
513ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
514 ClassTemplate, Liberal, ,
515 ImportConflictingDefAfterProto)
516
517ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
518 Function, Conservative, ,
519 DontImportConflictingDefAfterProto)
520ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
521 Variable, Conservative, ,
522 DontImportConflictingDefAfterProto)
523ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
524 ClassTemplate, Conservative, ,
525 DontImportConflictingDefAfterProto)
526
527ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
528 ClassTemplate, Liberal, ,
529 ImportConflictingProtoDefAfterProto)
530
531ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
532 ClassTemplate, Conservative, ,
533 DontImportConflictingProtoDefAfterProto)
534
535ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
536 ClassTemplate, Liberal, ,
537 ImportConflictingProtoAfterProtoDef)
538
539ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
540 ClassTemplate, Conservative, ,
541 DontImportConflictingProtoAfterProtoDef)
542
543ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
544 ClassTemplate, Liberal, ,
545 ImportConflictingProtoDefAfterDef)
546
547ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
548 ClassTemplate, Conservative, ,
549 DontImportConflictingProtoDefAfterDef)
550
551ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
552 ClassTemplate, Liberal, ,
553 ImportConflictingDefAfterProtoDef)
554
555ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
556 ClassTemplate, Conservative, ,
557 DontImportConflictingDefAfterProtoDef)
558
559// FunctionTemplate decls overload with each other. Thus, they are imported
560// always as a new node, independently from any ODRHandling strategy.
561//
562// Function template specializations are "full" specializations. Structural
563// equivalency does not check the body of functions, so we cannot create
564// conflicting function template specializations. Thus, ODR handling strategies
565// has nothing to do with function template specializations. Fully specialized
566// function templates are imported as new nodes if their template arguments are
567// different.
568ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
569 FunctionTemplate, Liberal, ,
570 ImportDifferentDefAfterDef)
571ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
572 FunctionTemplateSpec, Liberal, ,
573 ImportDifferentDefAfterDef)
574ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
575 FunctionTemplate, Conservative, ,
576 ImportDifferentDefAfterDef)
577ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
578 FunctionTemplateSpec, Conservative, ,
579 ImportDifferentDefAfterDef)
580ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
581 FunctionTemplate, Liberal, ,
582 DontImportSameDefAfterDef)
583ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
584 FunctionTemplateSpec, Liberal, ,
585 DontImportSameDefAfterDef)
586ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
587 FunctionTemplate, Conservative, ,
588 DontImportSameDefAfterDef)
589ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_SUITE(
590 FunctionTemplateSpec, Conservative, ,
591 DontImportSameDefAfterDef)
592
593// ======================
594// Instantiate the tests.
595// ======================
596
597// FIXME: These fail on Windows.
598#if !defined(_WIN32)
599INSTANTIATE_TEST_SUITE_P(
600 ODRViolationTests, FunctionConservative,
601 DefaultTestValuesForRunOptions );
602#else
603GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FunctionConservative);
604#endif
605INSTANTIATE_TEST_SUITE_P(
606 ODRViolationTests, TypedefConservative,
607 DefaultTestValuesForRunOptions );
608INSTANTIATE_TEST_SUITE_P(
609 ODRViolationTests, TypedefAliasConservative,
610 DefaultTestValuesForRunOptions );
611INSTANTIATE_TEST_SUITE_P(
612 ODRViolationTests, EnumConservative,
613 DefaultTestValuesForRunOptions );
614INSTANTIATE_TEST_SUITE_P(
615 ODRViolationTests, EnumClassConservative,
616 DefaultTestValuesForRunOptions );
617INSTANTIATE_TEST_SUITE_P(
618 ODRViolationTests, EnumConstantConservative,
619 DefaultTestValuesForRunOptions );
620INSTANTIATE_TEST_SUITE_P(
621 ODRViolationTests, ClassConservative,
622 DefaultTestValuesForRunOptions );
623INSTANTIATE_TEST_SUITE_P(
624 ODRViolationTests, VariableConservative,
625 DefaultTestValuesForRunOptions);
626INSTANTIATE_TEST_SUITE_P(
627 ODRViolationTests, ClassTemplateConservative,
628 DefaultTestValuesForRunOptions);
629INSTANTIATE_TEST_SUITE_P(
630 ODRViolationTests, FunctionTemplateConservative,
631 DefaultTestValuesForRunOptions);
632// FIXME: Make VarTemplate tests work.
633//INSTANTIATE_TEST_SUITE_P(
634 //ODRViolationTests, VarTemplateConservative,
635 //DefaultTestValuesForRunOptions);
636GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VarTemplateConservative);
637
638INSTANTIATE_TEST_SUITE_P(
639 ODRViolationTests, FunctionTemplateSpecConservative,
640 DefaultTestValuesForRunOptions);
641INSTANTIATE_TEST_SUITE_P(
642 ODRViolationTests, ClassTemplateSpecConservative,
643 DefaultTestValuesForRunOptions);
644// FIXME: Make VarTemplateSpec tests work.
645//INSTANTIATE_TEST_SUITE_P(
646 //ODRViolationTests, VarTemplateSpecConservative,
647 //DefaultTestValuesForRunOptions);
648GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VarTemplateSpecConservative);
649
650// FIXME: These fail on Windows.
651#if !defined(_WIN32)
652INSTANTIATE_TEST_SUITE_P(
653 ODRViolationTests, FunctionLiberal,
654 DefaultTestValuesForRunOptions);
655#else
656GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FunctionLiberal);
657#endif
658INSTANTIATE_TEST_SUITE_P(
659 ODRViolationTests, TypedefLiberal,
660 DefaultTestValuesForRunOptions);
661INSTANTIATE_TEST_SUITE_P(
662 ODRViolationTests, TypedefAliasLiberal,
663 DefaultTestValuesForRunOptions);
664INSTANTIATE_TEST_SUITE_P(
665 ODRViolationTests, EnumLiberal,
666 DefaultTestValuesForRunOptions);
667INSTANTIATE_TEST_SUITE_P(
668 ODRViolationTests, EnumClassLiberal,
669 DefaultTestValuesForRunOptions);
670INSTANTIATE_TEST_SUITE_P(
671 ODRViolationTests, EnumConstantLiberal,
672 DefaultTestValuesForRunOptions);
673INSTANTIATE_TEST_SUITE_P(
674 ODRViolationTests, ClassLiberal,
675 DefaultTestValuesForRunOptions);
676INSTANTIATE_TEST_SUITE_P(
677 ODRViolationTests, VariableLiberal,
678 DefaultTestValuesForRunOptions);
679INSTANTIATE_TEST_SUITE_P(
680 ODRViolationTests, ClassTemplateLiberal,
681 DefaultTestValuesForRunOptions);
682INSTANTIATE_TEST_SUITE_P(
683 ODRViolationTests, FunctionTemplateLiberal,
684 DefaultTestValuesForRunOptions);
685// FIXME: Make VarTemplate tests work.
686// INSTANTIATE_TEST_SUITE_P(
687// ODRViolationTests, VarTemplateLiberal,
688// DefaultTestValuesForRunOptions);
689GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VarTemplateLiberal);
690
691INSTANTIATE_TEST_SUITE_P(
692 ODRViolationTests, ClassTemplateSpecLiberal,
693 DefaultTestValuesForRunOptions);
694INSTANTIATE_TEST_SUITE_P(
695 ODRViolationTests, FunctionTemplateSpecLiberal,
696 DefaultTestValuesForRunOptions);
697// FIXME: Make VarTemplateSpec tests work.
698//INSTANTIATE_TEST_SUITE_P(
699 //ODRViolationTests, VarTemplateSpecLiberal,
700 //DefaultTestValuesForRunOptions );
701GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VarTemplateSpecLiberal);
702
703// clang-format on
704
705} // end namespace ast_matchers
706} // end namespace clang
707

source code of clang/unittests/AST/ASTImporterODRStrategiesTest.cpp