Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 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 Decls with different |
| 10 | // visibility. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | // Define this to have ::testing::Combine available. |
| 15 | // FIXME: Better solution for this? |
| 16 | #define GTEST_HAS_COMBINE 1 |
| 17 | |
| 18 | #include "ASTImporterFixtures.h" |
| 19 | |
| 20 | namespace clang { |
| 21 | namespace ast_matchers { |
| 22 | |
| 23 | using internal::BindableMatcher; |
| 24 | |
| 25 | // Type parameters for type-parameterized test fixtures. |
| 26 | struct GetFunPattern { |
| 27 | using DeclTy = FunctionDecl; |
| 28 | BindableMatcher<Decl> operator()() { return functionDecl(hasName("f")); } |
| 29 | }; |
| 30 | struct GetVarPattern { |
| 31 | using DeclTy = VarDecl; |
| 32 | BindableMatcher<Decl> operator()() { return varDecl(hasName("v")); } |
| 33 | }; |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 34 | struct GetClassPattern { |
| 35 | using DeclTy = CXXRecordDecl; |
| 36 | BindableMatcher<Decl> operator()() { return cxxRecordDecl(hasName("X")); } |
| 37 | }; |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 38 | struct GetEnumPattern { |
| 39 | using DeclTy = EnumDecl; |
| 40 | BindableMatcher<Decl> operator()() { return enumDecl(hasName("E")); } |
| 41 | }; |
Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 42 | struct GetTypedefNamePattern { |
| 43 | using DeclTy = TypedefNameDecl; |
| 44 | BindableMatcher<Decl> operator()() { return typedefNameDecl(hasName("T")); } |
| 45 | }; |
Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 46 | struct GetFunTemplPattern { |
| 47 | using DeclTy = FunctionTemplateDecl; |
| 48 | BindableMatcher<Decl> operator()() { |
| 49 | return functionTemplateDecl(hasName("f")); |
| 50 | } |
| 51 | }; |
Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 52 | struct GetClassTemplPattern { |
| 53 | using DeclTy = ClassTemplateDecl; |
| 54 | BindableMatcher<Decl> operator()() { return classTemplateDecl(hasName("X")); } |
| 55 | }; |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 56 | |
| 57 | // Values for the value-parameterized test fixtures. |
| 58 | // FunctionDecl: |
| 59 | const auto *ExternF = "void f();"; |
| 60 | const auto *StaticF = "static void f();"; |
| 61 | const auto *AnonF = "namespace { void f(); }"; |
| 62 | // VarDecl: |
| 63 | const auto *ExternV = "extern int v;"; |
| 64 | const auto *StaticV = "static int v;"; |
| 65 | const auto *AnonV = "namespace { extern int v; }"; |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 66 | // CXXRecordDecl: |
| 67 | const auto *ExternC = "class X;"; |
| 68 | const auto *AnonC = "namespace { class X; }"; |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 69 | // EnumDecl: |
| 70 | const auto *ExternE = "enum E {};"; |
| 71 | const auto *AnonE = "namespace { enum E {}; }"; |
Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 72 | // TypedefNameDecl: |
| 73 | const auto *ExternTypedef = "typedef int T;"; |
| 74 | const auto *AnonTypedef = "namespace { typedef int T; }"; |
| 75 | const auto *ExternUsing = "using T = int;"; |
| 76 | const auto *AnonUsing = "namespace { using T = int; }"; |
Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 77 | // FunctionTemplateDecl: |
| 78 | const auto *ExternFT = "template <class> void f();"; |
| 79 | const auto *StaticFT = "template <class> static void f();"; |
| 80 | const auto *AnonFT = "namespace { template <class> void f(); }"; |
Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 81 | // ClassTemplateDecl: |
| 82 | const auto *ExternCT = "template <class> class X;"; |
| 83 | const auto *AnonCT = "namespace { template <class> class X; }"; |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 84 | |
| 85 | // First value in tuple: Compile options. |
| 86 | // Second value in tuple: Source code to be used in the test. |
| 87 | using ImportVisibilityChainParams = |
| 88 | ::testing::WithParamInterface<std::tuple<ArgVector, const char *>>; |
| 89 | // Fixture to test the redecl chain of Decls with the same visibility. Gtest |
| 90 | // makes it possible to have either value-parameterized or type-parameterized |
| 91 | // fixtures. However, we cannot have both value- and type-parameterized test |
| 92 | // fixtures. This is a value-parameterized test fixture in the gtest sense. We |
| 93 | // intend to mimic gtest's type-parameters via the PatternFactory template |
| 94 | // parameter. We manually instantiate the different tests with the each types. |
| 95 | template <typename PatternFactory> |
| 96 | class ImportVisibilityChain |
| 97 | : public ASTImporterTestBase, public ImportVisibilityChainParams { |
| 98 | protected: |
| 99 | using DeclTy = typename PatternFactory::DeclTy; |
| 100 | ArgVector getExtraArgs() const override { return std::get<0>(GetParam()); } |
| 101 | std::string getCode() const { return std::get<1>(GetParam()); } |
| 102 | BindableMatcher<Decl> getPattern() const { return PatternFactory()(); } |
| 103 | |
| 104 | // Type-parameterized test. |
| 105 | void TypedTest_ImportChain() { |
| 106 | std::string Code = getCode() + getCode(); |
| 107 | auto Pattern = getPattern(); |
| 108 | |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 109 | TranslationUnitDecl *FromTu = getTuDecl(Code, Lang_CXX14, "input0.cc"); |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 110 | |
| 111 | auto *FromD0 = FirstDeclMatcher<DeclTy>().match(FromTu, Pattern); |
| 112 | auto *FromD1 = LastDeclMatcher<DeclTy>().match(FromTu, Pattern); |
| 113 | |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 114 | auto *ToD0 = Import(FromD0, Lang_CXX14); |
| 115 | auto *ToD1 = Import(FromD1, Lang_CXX14); |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 116 | |
| 117 | EXPECT_TRUE(ToD0); |
| 118 | ASSERT_TRUE(ToD1); |
| 119 | EXPECT_NE(ToD0, ToD1); |
| 120 | EXPECT_EQ(ToD1->getPreviousDecl(), ToD0); |
| 121 | } |
| 122 | }; |
| 123 | |
| 124 | // Manual instantiation of the fixture with each type. |
| 125 | using ImportFunctionsVisibilityChain = ImportVisibilityChain<GetFunPattern>; |
| 126 | using ImportVariablesVisibilityChain = ImportVisibilityChain<GetVarPattern>; |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 127 | using ImportClassesVisibilityChain = ImportVisibilityChain<GetClassPattern>; |
Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 128 | using ImportFunctionTemplatesVisibilityChain = |
| 129 | ImportVisibilityChain<GetFunTemplPattern>; |
Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 130 | using ImportClassTemplatesVisibilityChain = |
| 131 | ImportVisibilityChain<GetClassTemplPattern>; |
Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 132 | |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 133 | // Value-parameterized test for functions. |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 134 | TEST_P(ImportFunctionsVisibilityChain, ImportChain) { |
| 135 | TypedTest_ImportChain(); |
| 136 | } |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 137 | // Value-parameterized test for variables. |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 138 | TEST_P(ImportVariablesVisibilityChain, ImportChain) { |
| 139 | TypedTest_ImportChain(); |
| 140 | } |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 141 | // Value-parameterized test for classes. |
| 142 | TEST_P(ImportClassesVisibilityChain, ImportChain) { |
| 143 | TypedTest_ImportChain(); |
| 144 | } |
Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 145 | // Value-parameterized test for function templates. |
| 146 | TEST_P(ImportFunctionTemplatesVisibilityChain, ImportChain) { |
| 147 | TypedTest_ImportChain(); |
| 148 | } |
Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 149 | // Value-parameterized test for class templates. |
| 150 | TEST_P(ImportClassTemplatesVisibilityChain, ImportChain) { |
| 151 | TypedTest_ImportChain(); |
| 152 | } |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 153 | |
| 154 | // Automatic instantiation of the value-parameterized tests. |
| 155 | INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFunctionsVisibilityChain, |
| 156 | ::testing::Combine( |
| 157 | DefaultTestValuesForRunOptions, |
| 158 | ::testing::Values(ExternF, StaticF, AnonF)), ); |
| 159 | INSTANTIATE_TEST_CASE_P( |
| 160 | ParameterizedTests, ImportVariablesVisibilityChain, |
| 161 | ::testing::Combine( |
| 162 | DefaultTestValuesForRunOptions, |
| 163 | // There is no point to instantiate with StaticV, because in C++ we can |
| 164 | // forward declare a variable only with the 'extern' keyword. |
| 165 | // Consequently, each fwd declared variable has external linkage. This |
| 166 | // is different in the C language where any declaration without an |
| 167 | // initializer is a tentative definition, subsequent definitions may be |
| 168 | // provided but they must have the same linkage. See also the test |
| 169 | // ImportVariableChainInC which test for this special C Lang case. |
| 170 | ::testing::Values(ExternV, AnonV)), ); |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 171 | INSTANTIATE_TEST_CASE_P( |
| 172 | ParameterizedTests, ImportClassesVisibilityChain, |
| 173 | ::testing::Combine( |
| 174 | DefaultTestValuesForRunOptions, |
| 175 | ::testing::Values(ExternC, AnonC)), ); |
Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 176 | INSTANTIATE_TEST_CASE_P(ParameterizedTests, |
| 177 | ImportFunctionTemplatesVisibilityChain, |
| 178 | ::testing::Combine(DefaultTestValuesForRunOptions, |
| 179 | ::testing::Values(ExternFT, StaticFT, |
| 180 | AnonFT)), ); |
Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 181 | INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportClassTemplatesVisibilityChain, |
| 182 | ::testing::Combine(DefaultTestValuesForRunOptions, |
| 183 | ::testing::Values(ExternCT, |
| 184 | AnonCT)), ); |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 185 | |
| 186 | // First value in tuple: Compile options. |
| 187 | // Second value in tuple: Tuple with informations for the test. |
| 188 | // Code for first import (or initial code), code to import, whether the `f` |
| 189 | // functions are expected to be linked in a declaration chain. |
| 190 | // One value of this tuple is combined with every value of compile options. |
| 191 | // The test can have a single tuple as parameter only. |
| 192 | using ImportVisibilityParams = ::testing::WithParamInterface< |
| 193 | std::tuple<ArgVector, std::tuple<const char *, const char *, bool>>>; |
| 194 | |
| 195 | template <typename PatternFactory> |
| 196 | class ImportVisibility |
| 197 | : public ASTImporterTestBase, |
| 198 | public ImportVisibilityParams { |
| 199 | protected: |
| 200 | using DeclTy = typename PatternFactory::DeclTy; |
| 201 | ArgVector getExtraArgs() const override { return std::get<0>(GetParam()); } |
| 202 | std::string getCode0() const { return std::get<0>(std::get<1>(GetParam())); } |
| 203 | std::string getCode1() const { return std::get<1>(std::get<1>(GetParam())); } |
| 204 | bool shouldBeLinked() const { return std::get<2>(std::get<1>(GetParam())); } |
| 205 | BindableMatcher<Decl> getPattern() const { return PatternFactory()(); } |
| 206 | |
| 207 | void TypedTest_ImportAfter() { |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 208 | TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX14); |
| 209 | TranslationUnitDecl *FromTu = |
| 210 | getTuDecl(getCode1(), Lang_CXX14, "input1.cc"); |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 211 | |
| 212 | auto *ToD0 = FirstDeclMatcher<DeclTy>().match(ToTu, getPattern()); |
| 213 | auto *FromD1 = FirstDeclMatcher<DeclTy>().match(FromTu, getPattern()); |
| 214 | |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 215 | auto *ToD1 = Import(FromD1, Lang_CXX14); |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 216 | |
| 217 | ASSERT_TRUE(ToD0); |
| 218 | ASSERT_TRUE(ToD1); |
| 219 | EXPECT_NE(ToD0, ToD1); |
| 220 | |
| 221 | if (shouldBeLinked()) |
| 222 | EXPECT_EQ(ToD1->getPreviousDecl(), ToD0); |
| 223 | else |
| 224 | EXPECT_FALSE(ToD1->getPreviousDecl()); |
| 225 | } |
| 226 | |
| 227 | void TypedTest_ImportAfterImport() { |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 228 | TranslationUnitDecl *FromTu0 = |
| 229 | getTuDecl(getCode0(), Lang_CXX14, "input0.cc"); |
| 230 | TranslationUnitDecl *FromTu1 = |
| 231 | getTuDecl(getCode1(), Lang_CXX14, "input1.cc"); |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 232 | auto *FromD0 = FirstDeclMatcher<DeclTy>().match(FromTu0, getPattern()); |
| 233 | auto *FromD1 = FirstDeclMatcher<DeclTy>().match(FromTu1, getPattern()); |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 234 | auto *ToD0 = Import(FromD0, Lang_CXX14); |
| 235 | auto *ToD1 = Import(FromD1, Lang_CXX14); |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 236 | ASSERT_TRUE(ToD0); |
| 237 | ASSERT_TRUE(ToD1); |
| 238 | EXPECT_NE(ToD0, ToD1); |
| 239 | if (shouldBeLinked()) |
| 240 | EXPECT_EQ(ToD1->getPreviousDecl(), ToD0); |
| 241 | else |
| 242 | EXPECT_FALSE(ToD1->getPreviousDecl()); |
| 243 | } |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 244 | |
| 245 | void TypedTest_ImportAfterWithMerge() { |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 246 | TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX14); |
| 247 | TranslationUnitDecl *FromTu = |
| 248 | getTuDecl(getCode1(), Lang_CXX14, "input1.cc"); |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 249 | |
| 250 | auto *ToF0 = FirstDeclMatcher<DeclTy>().match(ToTu, getPattern()); |
| 251 | auto *FromF1 = FirstDeclMatcher<DeclTy>().match(FromTu, getPattern()); |
| 252 | |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 253 | auto *ToF1 = Import(FromF1, Lang_CXX14); |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 254 | |
| 255 | ASSERT_TRUE(ToF0); |
| 256 | ASSERT_TRUE(ToF1); |
| 257 | |
| 258 | if (shouldBeLinked()) |
| 259 | EXPECT_EQ(ToF0, ToF1); |
| 260 | else |
| 261 | EXPECT_NE(ToF0, ToF1); |
| 262 | |
| 263 | // We expect no (ODR) warning during the import. |
| 264 | EXPECT_EQ(0u, ToTu->getASTContext().getDiagnostics().getNumWarnings()); |
| 265 | } |
| 266 | |
| 267 | void TypedTest_ImportAfterImportWithMerge() { |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 268 | TranslationUnitDecl *FromTu0 = |
| 269 | getTuDecl(getCode0(), Lang_CXX14, "input0.cc"); |
| 270 | TranslationUnitDecl *FromTu1 = |
| 271 | getTuDecl(getCode1(), Lang_CXX14, "input1.cc"); |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 272 | auto *FromF0 = FirstDeclMatcher<DeclTy>().match(FromTu0, getPattern()); |
| 273 | auto *FromF1 = FirstDeclMatcher<DeclTy>().match(FromTu1, getPattern()); |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 274 | auto *ToF0 = Import(FromF0, Lang_CXX14); |
| 275 | auto *ToF1 = Import(FromF1, Lang_CXX14); |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 276 | ASSERT_TRUE(ToF0); |
| 277 | ASSERT_TRUE(ToF1); |
| 278 | if (shouldBeLinked()) |
| 279 | EXPECT_EQ(ToF0, ToF1); |
| 280 | else |
| 281 | EXPECT_NE(ToF0, ToF1); |
| 282 | |
| 283 | // We expect no (ODR) warning during the import. |
| 284 | EXPECT_EQ(0u, ToF0->getTranslationUnitDecl() |
| 285 | ->getASTContext() |
| 286 | .getDiagnostics() |
| 287 | .getNumWarnings()); |
| 288 | } |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 289 | }; |
| 290 | using ImportFunctionsVisibility = ImportVisibility<GetFunPattern>; |
| 291 | using ImportVariablesVisibility = ImportVisibility<GetVarPattern>; |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 292 | using ImportClassesVisibility = ImportVisibility<GetClassPattern>; |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 293 | using ImportEnumsVisibility = ImportVisibility<GetEnumPattern>; |
Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 294 | using ImportTypedefNameVisibility = ImportVisibility<GetTypedefNamePattern>; |
Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 295 | using ImportFunctionTemplatesVisibility = ImportVisibility<GetFunTemplPattern>; |
Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 296 | using ImportClassTemplatesVisibility = ImportVisibility<GetClassTemplPattern>; |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 297 | |
| 298 | // FunctionDecl. |
| 299 | TEST_P(ImportFunctionsVisibility, ImportAfter) { |
| 300 | TypedTest_ImportAfter(); |
| 301 | } |
| 302 | TEST_P(ImportFunctionsVisibility, ImportAfterImport) { |
| 303 | TypedTest_ImportAfterImport(); |
| 304 | } |
| 305 | // VarDecl. |
| 306 | TEST_P(ImportVariablesVisibility, ImportAfter) { |
| 307 | TypedTest_ImportAfter(); |
| 308 | } |
| 309 | TEST_P(ImportVariablesVisibility, ImportAfterImport) { |
| 310 | TypedTest_ImportAfterImport(); |
| 311 | } |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 312 | // CXXRecordDecl. |
| 313 | TEST_P(ImportClassesVisibility, ImportAfter) { |
| 314 | TypedTest_ImportAfter(); |
| 315 | } |
| 316 | TEST_P(ImportClassesVisibility, ImportAfterImport) { |
| 317 | TypedTest_ImportAfterImport(); |
| 318 | } |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 319 | // EnumDecl. |
| 320 | TEST_P(ImportEnumsVisibility, ImportAfter) { |
| 321 | TypedTest_ImportAfterWithMerge(); |
| 322 | } |
| 323 | TEST_P(ImportEnumsVisibility, ImportAfterImport) { |
| 324 | TypedTest_ImportAfterImportWithMerge(); |
| 325 | } |
Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 326 | // TypedefNameDecl. |
| 327 | TEST_P(ImportTypedefNameVisibility, ImportAfter) { |
| 328 | TypedTest_ImportAfterWithMerge(); |
| 329 | } |
| 330 | TEST_P(ImportTypedefNameVisibility, ImportAfterImport) { |
| 331 | TypedTest_ImportAfterImportWithMerge(); |
| 332 | } |
Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 333 | // FunctionTemplateDecl. |
| 334 | TEST_P(ImportFunctionTemplatesVisibility, ImportAfter) { |
| 335 | TypedTest_ImportAfter(); |
| 336 | } |
| 337 | TEST_P(ImportFunctionTemplatesVisibility, ImportAfterImport) { |
| 338 | TypedTest_ImportAfterImport(); |
| 339 | } |
Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 340 | // ClassTemplateDecl. |
| 341 | TEST_P(ImportClassTemplatesVisibility, ImportAfter) { TypedTest_ImportAfter(); } |
| 342 | TEST_P(ImportClassTemplatesVisibility, ImportAfterImport) { |
| 343 | TypedTest_ImportAfterImport(); |
| 344 | } |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 345 | |
Balazs Keri | caa4279 | 2019-09-05 07:59:45 +0000 | [diff] [blame] | 346 | const bool ExpectLinkedDeclChain = true; |
| 347 | const bool ExpectUnlinkedDeclChain = false; |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 348 | |
| 349 | INSTANTIATE_TEST_CASE_P( |
| 350 | ParameterizedTests, ImportFunctionsVisibility, |
| 351 | ::testing::Combine( |
| 352 | DefaultTestValuesForRunOptions, |
Balazs Keri | caa4279 | 2019-09-05 07:59:45 +0000 | [diff] [blame] | 353 | ::testing::Values( |
| 354 | std::make_tuple(ExternF, ExternF, ExpectLinkedDeclChain), |
| 355 | std::make_tuple(ExternF, StaticF, ExpectUnlinkedDeclChain), |
| 356 | std::make_tuple(ExternF, AnonF, ExpectUnlinkedDeclChain), |
| 357 | std::make_tuple(StaticF, ExternF, ExpectUnlinkedDeclChain), |
| 358 | std::make_tuple(StaticF, StaticF, ExpectUnlinkedDeclChain), |
| 359 | std::make_tuple(StaticF, AnonF, ExpectUnlinkedDeclChain), |
| 360 | std::make_tuple(AnonF, ExternF, ExpectUnlinkedDeclChain), |
| 361 | std::make_tuple(AnonF, StaticF, ExpectUnlinkedDeclChain), |
| 362 | std::make_tuple(AnonF, AnonF, ExpectUnlinkedDeclChain))), ); |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 363 | INSTANTIATE_TEST_CASE_P( |
| 364 | ParameterizedTests, ImportVariablesVisibility, |
| 365 | ::testing::Combine( |
| 366 | DefaultTestValuesForRunOptions, |
Balazs Keri | caa4279 | 2019-09-05 07:59:45 +0000 | [diff] [blame] | 367 | ::testing::Values( |
| 368 | std::make_tuple(ExternV, ExternV, ExpectLinkedDeclChain), |
| 369 | std::make_tuple(ExternV, StaticV, ExpectUnlinkedDeclChain), |
| 370 | std::make_tuple(ExternV, AnonV, ExpectUnlinkedDeclChain), |
| 371 | std::make_tuple(StaticV, ExternV, ExpectUnlinkedDeclChain), |
| 372 | std::make_tuple(StaticV, StaticV, ExpectUnlinkedDeclChain), |
| 373 | std::make_tuple(StaticV, AnonV, ExpectUnlinkedDeclChain), |
| 374 | std::make_tuple(AnonV, ExternV, ExpectUnlinkedDeclChain), |
| 375 | std::make_tuple(AnonV, StaticV, ExpectUnlinkedDeclChain), |
| 376 | std::make_tuple(AnonV, AnonV, ExpectUnlinkedDeclChain))), ); |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 377 | INSTANTIATE_TEST_CASE_P( |
| 378 | ParameterizedTests, ImportClassesVisibility, |
| 379 | ::testing::Combine( |
| 380 | DefaultTestValuesForRunOptions, |
Balazs Keri | caa4279 | 2019-09-05 07:59:45 +0000 | [diff] [blame] | 381 | ::testing::Values( |
| 382 | std::make_tuple(ExternC, ExternC, ExpectLinkedDeclChain), |
| 383 | std::make_tuple(ExternC, AnonC, ExpectUnlinkedDeclChain), |
| 384 | std::make_tuple(AnonC, ExternC, ExpectUnlinkedDeclChain), |
| 385 | std::make_tuple(AnonC, AnonC, ExpectUnlinkedDeclChain))), ); |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 386 | INSTANTIATE_TEST_CASE_P( |
| 387 | ParameterizedTests, ImportEnumsVisibility, |
| 388 | ::testing::Combine( |
| 389 | DefaultTestValuesForRunOptions, |
Balazs Keri | caa4279 | 2019-09-05 07:59:45 +0000 | [diff] [blame] | 390 | ::testing::Values( |
| 391 | std::make_tuple(ExternE, ExternE, ExpectLinkedDeclChain), |
| 392 | std::make_tuple(ExternE, AnonE, ExpectUnlinkedDeclChain), |
| 393 | std::make_tuple(AnonE, ExternE, ExpectUnlinkedDeclChain), |
| 394 | std::make_tuple(AnonE, AnonE, ExpectUnlinkedDeclChain))), ); |
Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 395 | INSTANTIATE_TEST_CASE_P( |
| 396 | ParameterizedTests, ImportTypedefNameVisibility, |
| 397 | ::testing::Combine( |
| 398 | DefaultTestValuesForRunOptions, |
| 399 | ::testing::Values( |
Balazs Keri | caa4279 | 2019-09-05 07:59:45 +0000 | [diff] [blame] | 400 | std::make_tuple(ExternTypedef, ExternTypedef, |
| 401 | ExpectLinkedDeclChain), |
| 402 | std::make_tuple(ExternTypedef, AnonTypedef, |
| 403 | ExpectUnlinkedDeclChain), |
| 404 | std::make_tuple(AnonTypedef, ExternTypedef, |
| 405 | ExpectUnlinkedDeclChain), |
| 406 | std::make_tuple(AnonTypedef, AnonTypedef, ExpectUnlinkedDeclChain), |
Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 407 | |
Balazs Keri | caa4279 | 2019-09-05 07:59:45 +0000 | [diff] [blame] | 408 | std::make_tuple(ExternUsing, ExternUsing, ExpectLinkedDeclChain), |
| 409 | std::make_tuple(ExternUsing, AnonUsing, ExpectUnlinkedDeclChain), |
| 410 | std::make_tuple(AnonUsing, ExternUsing, ExpectUnlinkedDeclChain), |
| 411 | std::make_tuple(AnonUsing, AnonUsing, ExpectUnlinkedDeclChain), |
Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 412 | |
Balazs Keri | caa4279 | 2019-09-05 07:59:45 +0000 | [diff] [blame] | 413 | std::make_tuple(ExternUsing, ExternTypedef, ExpectLinkedDeclChain), |
| 414 | std::make_tuple(ExternUsing, AnonTypedef, ExpectUnlinkedDeclChain), |
| 415 | std::make_tuple(AnonUsing, ExternTypedef, ExpectUnlinkedDeclChain), |
| 416 | std::make_tuple(AnonUsing, AnonTypedef, ExpectUnlinkedDeclChain), |
Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 417 | |
Balazs Keri | caa4279 | 2019-09-05 07:59:45 +0000 | [diff] [blame] | 418 | std::make_tuple(ExternTypedef, ExternUsing, ExpectLinkedDeclChain), |
| 419 | std::make_tuple(ExternTypedef, AnonUsing, ExpectUnlinkedDeclChain), |
| 420 | std::make_tuple(AnonTypedef, ExternUsing, ExpectUnlinkedDeclChain), |
| 421 | std::make_tuple(AnonTypedef, AnonUsing, |
| 422 | ExpectUnlinkedDeclChain))), ); |
Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 423 | INSTANTIATE_TEST_CASE_P( |
| 424 | ParameterizedTests, ImportFunctionTemplatesVisibility, |
| 425 | ::testing::Combine( |
| 426 | DefaultTestValuesForRunOptions, |
| 427 | ::testing::Values( |
| 428 | std::make_tuple(ExternFT, ExternFT, ExpectLinkedDeclChain), |
| 429 | std::make_tuple(ExternFT, StaticFT, ExpectUnlinkedDeclChain), |
| 430 | std::make_tuple(ExternFT, AnonFT, ExpectUnlinkedDeclChain), |
| 431 | std::make_tuple(StaticFT, ExternFT, ExpectUnlinkedDeclChain), |
| 432 | std::make_tuple(StaticFT, StaticFT, ExpectUnlinkedDeclChain), |
| 433 | std::make_tuple(StaticFT, AnonFT, ExpectUnlinkedDeclChain), |
| 434 | std::make_tuple(AnonFT, ExternFT, ExpectUnlinkedDeclChain), |
| 435 | std::make_tuple(AnonFT, StaticFT, ExpectUnlinkedDeclChain), |
| 436 | std::make_tuple(AnonFT, AnonFT, ExpectUnlinkedDeclChain))), ); |
Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 437 | INSTANTIATE_TEST_CASE_P( |
| 438 | ParameterizedTests, ImportClassTemplatesVisibility, |
| 439 | ::testing::Combine( |
| 440 | DefaultTestValuesForRunOptions, |
| 441 | ::testing::Values(std::make_tuple(ExternCT, ExternCT, ExpectLinkedDeclChain), |
| 442 | std::make_tuple(ExternCT, AnonCT, ExpectUnlinkedDeclChain), |
| 443 | std::make_tuple(AnonCT, ExternCT, ExpectUnlinkedDeclChain), |
| 444 | std::make_tuple(AnonCT, AnonCT, ExpectUnlinkedDeclChain))), ); |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 445 | } // end namespace ast_matchers |
| 446 | } // end namespace clang |