ASTImporterODRStrategiesTest.cpp 24 KB

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