Index: unittests/AST/ASTImporterTest.cpp =================================================================== --- unittests/AST/ASTImporterTest.cpp +++ unittests/AST/ASTImporterTest.cpp @@ -151,6 +151,25 @@ Verifier, AMatcher)); } +template +void testImport(const std::string &FromCode, + Language FromLang, const ArgVector &FromArgsExtra, + const std::string &ToCode, + Language ToLang, const ArgVector &ToArgsExtra, + MatchVerifier &Verifier, + const MatcherType &AMatcher) { + auto RunOptsFrom = getRunOptionsForLanguage(FromLang); + auto RunOptsTo = getRunOptionsForLanguage(ToLang); + for (auto FromArgs : RunOptsFrom) { + for (auto ToArgs : RunOptsTo) { + FromArgs.insert(FromArgs.end(), FromArgsExtra.begin(), FromArgsExtra.end()); + ToArgs.insert(ToArgs.end(), ToArgsExtra.begin(), ToArgsExtra.end()); + EXPECT_TRUE(testImport(FromCode, FromArgs, ToCode, ToArgs, + Verifier, AMatcher)); + } + } +} + // This class provides generic methods to write tests which can check internal // attributes of AST nodes like getPreviousDecl(), isVirtual(), etc. Also, // this fixture makes it possible to import from several "From" contexts. @@ -428,7 +447,7 @@ TEST(ImportExpr, ImportStringLiteral) { MatchVerifier Verifier; testImport("void declToImport() { \"foo\"; }", - Lang_CXX, "", Lang_CXX, Verifier, + Lang_CXX, { "-Wno-unused-value" }, "", Lang_CXX, {}, Verifier, functionDecl( hasBody( compoundStmt( @@ -437,7 +456,7 @@ hasType( asString("const char [4]")))))))); testImport("void declToImport() { L\"foo\"; }", - Lang_CXX, "", Lang_CXX, Verifier, + Lang_CXX, { "-Wno-unused-value" }, "", Lang_CXX, {}, Verifier, functionDecl( hasBody( compoundStmt( @@ -446,7 +465,7 @@ hasType( asString("const wchar_t [4]")))))))); testImport("void declToImport() { \"foo\" \"bar\"; }", - Lang_CXX, "", Lang_CXX, Verifier, + Lang_CXX, { "-Wno-unused-value" }, "", Lang_CXX, {}, Verifier, functionDecl( hasBody( compoundStmt( @@ -459,7 +478,7 @@ TEST(ImportExpr, ImportGNUNullExpr) { MatchVerifier Verifier; testImport("void declToImport() { __null; }", - Lang_CXX, "", Lang_CXX, Verifier, + Lang_CXX, { "-Wno-unused-value" }, "", Lang_CXX, {}, Verifier, functionDecl( hasBody( compoundStmt( @@ -471,7 +490,7 @@ TEST(ImportExpr, ImportCXXNullPtrLiteralExpr) { MatchVerifier Verifier; testImport("void declToImport() { nullptr; }", - Lang_CXX11, "", Lang_CXX11, Verifier, + Lang_CXX11, { "-Wno-unused-value" }, "", Lang_CXX11, {}, Verifier, functionDecl( hasBody( compoundStmt( @@ -483,7 +502,7 @@ TEST(ImportExpr, ImportFloatinglLiteralExpr) { MatchVerifier Verifier; testImport("void declToImport() { 1.0; }", - Lang_C, "", Lang_C, Verifier, + Lang_C, { "-Wno-unused-value" }, "", Lang_C, {}, Verifier, functionDecl( hasBody( compoundStmt( @@ -492,7 +511,7 @@ equals(1.0), hasType(asString("double")))))))); testImport("void declToImport() { 1.0e-5f; }", - Lang_C, "", Lang_C, Verifier, + Lang_C, { "-Wno-unused-value" }, "", Lang_C, {}, Verifier, functionDecl( hasBody( compoundStmt( @@ -507,7 +526,7 @@ testImport("void declToImport() {" " struct s { int x; long y; unsigned z; }; " " (struct s){ 42, 0L, 1U }; }", - Lang_CXX, "", Lang_CXX, Verifier, + Lang_CXX, { "-Wno-unused-value" }, "", Lang_CXX, {}, Verifier, functionDecl( hasBody( compoundStmt( @@ -529,7 +548,7 @@ TEST(ImportExpr, ImportCXXThisExpr) { MatchVerifier Verifier; testImport("class declToImport { void f() { this; } };", - Lang_CXX, "", Lang_CXX, Verifier, + Lang_CXX, { "-Wno-unused-value" }, "", Lang_CXX, {}, Verifier, cxxRecordDecl( hasMethod( hasBody( @@ -554,7 +573,8 @@ TEST(ImportExpr, ImportLabelDeclAndAddrLabelExpr) { MatchVerifier Verifier; testImport( - "void declToImport() { loop: goto loop; &&loop; }", Lang_C, "", Lang_C, + "void declToImport() { loop: goto loop; &&loop; }", + Lang_C, { "-Wno-unused-value" }, "", Lang_C, {}, Verifier, functionDecl(hasBody(compoundStmt( has(labelStmt(hasDeclaration(labelDecl(hasName("loop"))))), @@ -626,7 +646,7 @@ MatchVerifier Verifier; testImport( "void declToImport() { true ? 1 : -5; }", - Lang_CXX, "", Lang_CXX, Verifier, + Lang_CXX, { "-Wno-unused-value" }, "", Lang_CXX, {}, Verifier, functionDecl( hasBody( compoundStmt( @@ -642,7 +662,8 @@ TEST(ImportExpr, ImportBinaryConditionalOperator) { MatchVerifier Verifier; testImport( - "void declToImport() { 1 ?: -5; }", Lang_CXX, "", Lang_CXX, Verifier, + "void declToImport() { 1 ?: -5; }", + Lang_CXX, { "-Wno-unused-value" }, "", Lang_CXX, {}, Verifier, functionDecl( hasBody( compoundStmt( @@ -710,7 +731,7 @@ MatchVerifier Verifier; // __func__ expands as StringLiteral("declToImport") testImport("void declToImport() { __func__; }", - Lang_CXX, "", Lang_CXX, Verifier, + Lang_CXX, { "-Wno-unused-value" }, "", Lang_CXX, {}, Verifier, functionDecl( hasBody( compoundStmt( @@ -817,7 +838,7 @@ " d.t;" "}" "void instantiate() { declToImport(); }", - Lang_CXX, "", Lang_CXX, Verifier, + Lang_CXX, { "-Wno-unused-value" }, "", Lang_CXX, {}, Verifier, functionTemplateDecl(has(functionDecl( has(compoundStmt(has(cxxDependentScopeMemberExpr()))))))); testImport("template struct C { T t; };" @@ -826,7 +847,7 @@ " (&d)->t;" "}" "void instantiate() { declToImport(); }", - Lang_CXX, "", Lang_CXX, Verifier, + Lang_CXX, { "-Wno-unused-value" }, "", Lang_CXX, {}, Verifier, functionTemplateDecl(has(functionDecl( has(compoundStmt(has(cxxDependentScopeMemberExpr()))))))); } @@ -854,7 +875,7 @@ "template " "T pi = T(3.1415926535897932385L);" "void declToImport() { pi; }", - Lang_CXX11, "", Lang_CXX11, Verifier, + Lang_CXX14, { "-Wno-unused-value" }, "", Lang_CXX14, {}, Verifier, functionDecl( hasBody(has(declRefExpr(to(varTemplateSpecializationDecl())))), unless(hasAncestor(translationUnitDecl(has(varDecl( @@ -939,7 +960,7 @@ testImport("void declToImport() { " " __builtin_types_compatible_p(int, int);" "}", - Lang_C, "", Lang_C, Verifier, + Lang_C, { "-Wno-unused-value" }, "", Lang_C, {}, Verifier, functionDecl( hasBody( compoundStmt( @@ -971,7 +992,7 @@ " void m() { __is_pod(T); }" "};" "void f() { declToImport().m(); }", - Lang_CXX11, "", Lang_CXX11, Verifier, + Lang_CXX11, { "-Wno-unused-value" }, "", Lang_CXX11, {}, Verifier, classTemplateDecl( has( cxxRecordDecl( @@ -1043,7 +1064,7 @@ " ::template foo;" "}" "void instantiate() { declToImport(); }", - Lang_CXX, "", Lang_CXX, Verifier, + Lang_CXX, { "-Wno-unused-value" }, "", Lang_CXX, {}, Verifier, functionTemplateDecl(has(functionDecl( has(compoundStmt(has(unresolvedLookupExpr()))))))); } @@ -1851,7 +1872,10 @@ " (void) S::foo;" "}" "void instantiate() { declToImport(); }", - Lang_CXX11, "", Lang_CXX11, Verifier, + Lang_CXX11, { "-Wno-undefined-var-template" }, + "", + Lang_CXX11, {}, + Verifier, functionTemplateDecl(has(functionDecl(has(compoundStmt( has(cStyleCastExpr(has(dependentScopeDeclRefExpr()))))))))); @@ -1862,7 +1886,10 @@ " S::template foo();" "}" "void instantiate() { declToImport(); }", - Lang_CXX11, "", Lang_CXX11, Verifier, + Lang_CXX11, { "-Wno-undefined-var-template" }, + "", + Lang_CXX11, {}, + Verifier, functionTemplateDecl(has(functionDecl(has(compoundStmt( has(callExpr(has(dependentScopeDeclRefExpr()))))))))); }