From: Nathan James Date: Mon, 1 Jun 2020 06:52:01 +0000 (+0100) Subject: [ASTMatchers] Force c++ unittests to specify correct language standard X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b6d23f2efc64c226d30094bcc4258e0b63029da8;p=platform%2Fupstream%2Fllvm.git [ASTMatchers] Force c++ unittests to specify correct language standard Force the unittests on c++ code for matchers to specify the correct standard. Reviewed By: gribozavr2 Differential Revision: https://reviews.llvm.org/D80884 --- diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.h b/clang/unittests/ASTMatchers/ASTMatchersTest.h index 6af039e..8bf23a5 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.h +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.h @@ -153,7 +153,7 @@ matchesConditionally(const std::string &Code, const T &AMatcher, } for (auto Mode : LangModes) { - std::string LangModeArg; + StringRef LangModeArg; switch (Mode) { case LanguageMode::Cxx11: LangModeArg = "-std=c++11"; @@ -171,8 +171,10 @@ matchesConditionally(const std::string &Code, const T &AMatcher, llvm_unreachable("Invalid language mode"); } - auto Result = - matchesConditionally(Code, AMatcher, ExpectMatch, LangModeArg); + auto Result = matchesConditionally(Code, AMatcher, ExpectMatch, + {LangModeArg, "-Werror=c++14-extensions", + "-Werror=c++17-extensions", + "-Werror=c++20-extensions"}); if (!Result) return Result; } diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp index 6bd8fcf6..93b0eef 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp @@ -950,10 +950,14 @@ TEST(TemplateTypeParmDecl, VarTemplatePartialSpecializationDecl) { "template\n" "template\n" "int Struct::field = 123;\n"; - EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("T")))); - EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("T2")))); - EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("U")))); - EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("U2")))); + EXPECT_TRUE( + matches(input, templateTypeParmDecl(hasName("T")), LanguageMode::Cxx14)); + EXPECT_TRUE( + matches(input, templateTypeParmDecl(hasName("T2")), LanguageMode::Cxx14)); + EXPECT_TRUE( + matches(input, templateTypeParmDecl(hasName("U")), LanguageMode::Cxx14)); + EXPECT_TRUE( + matches(input, templateTypeParmDecl(hasName("U2")), LanguageMode::Cxx14)); } TEST(TemplateTypeParmDecl, ClassTemplatePartialSpecializationDecl) { @@ -2061,113 +2065,146 @@ void func14() { )cpp"; - EXPECT_TRUE(matches( - Code, traverse(TK_IgnoreUnlessSpelledInSource, - returnStmt(forFunction(functionDecl(hasName("func1"))), - hasReturnValue(integerLiteral(equals(42))))))); + EXPECT_TRUE( + matches(Code, + traverse(TK_IgnoreUnlessSpelledInSource, + returnStmt(forFunction(functionDecl(hasName("func1"))), + hasReturnValue(integerLiteral(equals(42))))), + LanguageMode::Cxx2a)); - EXPECT_TRUE(matches( - Code, traverse(TK_IgnoreUnlessSpelledInSource, - integerLiteral(equals(42), - hasParent(returnStmt(forFunction( - functionDecl(hasName("func1"))))))))); + EXPECT_TRUE( + matches(Code, + traverse(TK_IgnoreUnlessSpelledInSource, + integerLiteral(equals(42), + hasParent(returnStmt(forFunction( + functionDecl(hasName("func1"))))))), + LanguageMode::Cxx2a)); EXPECT_TRUE(matches( Code, traverse(TK_IgnoreUnlessSpelledInSource, returnStmt(forFunction(functionDecl(hasName("func2"))), hasReturnValue(cxxTemporaryObjectExpr( - hasArgument(0, integerLiteral(equals(42))))))))); + hasArgument(0, integerLiteral(equals(42))))))), + LanguageMode::Cxx2a)); EXPECT_TRUE(matches( Code, - traverse(TK_IgnoreUnlessSpelledInSource, - integerLiteral( - equals(42), - hasParent(cxxTemporaryObjectExpr(hasParent(returnStmt( - forFunction(functionDecl(hasName("func2"))))))))))); + traverse( + TK_IgnoreUnlessSpelledInSource, + integerLiteral(equals(42), + hasParent(cxxTemporaryObjectExpr(hasParent(returnStmt( + forFunction(functionDecl(hasName("func2"))))))))), + LanguageMode::Cxx2a)); EXPECT_TRUE(matches( - Code, traverse(TK_IgnoreUnlessSpelledInSource, - returnStmt(forFunction(functionDecl(hasName("func3"))), - hasReturnValue( - cxxFunctionalCastExpr(hasSourceExpression( - integerLiteral(equals(42))))))))); + Code, + traverse( + TK_IgnoreUnlessSpelledInSource, + returnStmt(forFunction(functionDecl(hasName("func3"))), + hasReturnValue(cxxFunctionalCastExpr( + hasSourceExpression(integerLiteral(equals(42))))))), + LanguageMode::Cxx2a)); EXPECT_TRUE(matches( Code, - traverse(TK_IgnoreUnlessSpelledInSource, - integerLiteral( - equals(42), - hasParent(cxxFunctionalCastExpr(hasParent(returnStmt( - forFunction(functionDecl(hasName("func3"))))))))))); + traverse( + TK_IgnoreUnlessSpelledInSource, + integerLiteral(equals(42), + hasParent(cxxFunctionalCastExpr(hasParent(returnStmt( + forFunction(functionDecl(hasName("func3"))))))))), + LanguageMode::Cxx2a)); - EXPECT_TRUE(matches( - Code, traverse(TK_IgnoreUnlessSpelledInSource, - returnStmt(forFunction(functionDecl(hasName("func4"))), - hasReturnValue(cxxTemporaryObjectExpr()))))); + EXPECT_TRUE( + matches(Code, + traverse(TK_IgnoreUnlessSpelledInSource, + returnStmt(forFunction(functionDecl(hasName("func4"))), + hasReturnValue(cxxTemporaryObjectExpr()))), + LanguageMode::Cxx2a)); - EXPECT_TRUE(matches( - Code, traverse(TK_IgnoreUnlessSpelledInSource, - returnStmt(forFunction(functionDecl(hasName("func5"))), - hasReturnValue(cxxTemporaryObjectExpr()))))); + EXPECT_TRUE( + matches(Code, + traverse(TK_IgnoreUnlessSpelledInSource, + returnStmt(forFunction(functionDecl(hasName("func5"))), + hasReturnValue(cxxTemporaryObjectExpr()))), + LanguageMode::Cxx2a)); - EXPECT_TRUE(matches( - Code, traverse(TK_IgnoreUnlessSpelledInSource, - returnStmt(forFunction(functionDecl(hasName("func6"))), - hasReturnValue(cxxTemporaryObjectExpr()))))); + EXPECT_TRUE( + matches(Code, + traverse(TK_IgnoreUnlessSpelledInSource, + returnStmt(forFunction(functionDecl(hasName("func6"))), + hasReturnValue(cxxTemporaryObjectExpr()))), + LanguageMode::Cxx2a)); - EXPECT_TRUE(matches( - Code, traverse(TK_IgnoreUnlessSpelledInSource, - returnStmt(forFunction(functionDecl(hasName("func7"))), - hasReturnValue(cxxTemporaryObjectExpr()))))); + EXPECT_TRUE( + matches(Code, + traverse(TK_IgnoreUnlessSpelledInSource, + returnStmt(forFunction(functionDecl(hasName("func7"))), + hasReturnValue(cxxTemporaryObjectExpr()))), + LanguageMode::Cxx2a)); - EXPECT_TRUE(matches( - Code, traverse(TK_IgnoreUnlessSpelledInSource, - returnStmt(forFunction(functionDecl(hasName("func8"))), - hasReturnValue(cxxFunctionalCastExpr( - hasSourceExpression(initListExpr()))))))); + EXPECT_TRUE( + matches(Code, + traverse(TK_IgnoreUnlessSpelledInSource, + returnStmt(forFunction(functionDecl(hasName("func8"))), + hasReturnValue(cxxFunctionalCastExpr( + hasSourceExpression(initListExpr()))))), + LanguageMode::Cxx2a)); - EXPECT_TRUE(matches( - Code, traverse(TK_IgnoreUnlessSpelledInSource, - returnStmt(forFunction(functionDecl(hasName("func9"))), - hasReturnValue(cxxFunctionalCastExpr( - hasSourceExpression(initListExpr()))))))); + EXPECT_TRUE( + matches(Code, + traverse(TK_IgnoreUnlessSpelledInSource, + returnStmt(forFunction(functionDecl(hasName("func9"))), + hasReturnValue(cxxFunctionalCastExpr( + hasSourceExpression(initListExpr()))))), + LanguageMode::Cxx2a)); EXPECT_TRUE(matches( - Code, traverse(TK_IgnoreUnlessSpelledInSource, - returnStmt(forFunction(functionDecl(hasName("func10"))), - hasReturnValue( - declRefExpr(to(varDecl(hasName("a"))))))))); + Code, + traverse( + TK_IgnoreUnlessSpelledInSource, + returnStmt(forFunction(functionDecl(hasName("func10"))), + hasReturnValue(declRefExpr(to(varDecl(hasName("a"))))))), + LanguageMode::Cxx2a)); - EXPECT_TRUE(matches( - Code, traverse(TK_IgnoreUnlessSpelledInSource, - declRefExpr(to(varDecl(hasName("a"))), - hasParent(returnStmt(forFunction( - functionDecl(hasName("func10"))))))))); + EXPECT_TRUE( + matches(Code, + traverse(TK_IgnoreUnlessSpelledInSource, + declRefExpr(to(varDecl(hasName("a"))), + hasParent(returnStmt(forFunction( + functionDecl(hasName("func10"))))))), + LanguageMode::Cxx2a)); EXPECT_TRUE(matches( - Code, traverse(TK_IgnoreUnlessSpelledInSource, - returnStmt(forFunction(functionDecl(hasName("func11"))), - hasReturnValue( - declRefExpr(to(varDecl(hasName("b"))))))))); + Code, + traverse( + TK_IgnoreUnlessSpelledInSource, + returnStmt(forFunction(functionDecl(hasName("func11"))), + hasReturnValue(declRefExpr(to(varDecl(hasName("b"))))))), + LanguageMode::Cxx2a)); - EXPECT_TRUE(matches( - Code, traverse(TK_IgnoreUnlessSpelledInSource, - declRefExpr(to(varDecl(hasName("b"))), - hasParent(returnStmt(forFunction( - functionDecl(hasName("func11"))))))))); + EXPECT_TRUE( + matches(Code, + traverse(TK_IgnoreUnlessSpelledInSource, + declRefExpr(to(varDecl(hasName("b"))), + hasParent(returnStmt(forFunction( + functionDecl(hasName("func11"))))))), + LanguageMode::Cxx2a)); EXPECT_TRUE(matches( - Code, traverse(TK_IgnoreUnlessSpelledInSource, - returnStmt(forFunction(functionDecl(hasName("func12"))), - hasReturnValue( - declRefExpr(to(varDecl(hasName("c"))))))))); + Code, + traverse( + TK_IgnoreUnlessSpelledInSource, + returnStmt(forFunction(functionDecl(hasName("func12"))), + hasReturnValue(declRefExpr(to(varDecl(hasName("c"))))))), + LanguageMode::Cxx2a)); - EXPECT_TRUE(matches( - Code, traverse(TK_IgnoreUnlessSpelledInSource, - declRefExpr(to(varDecl(hasName("c"))), - hasParent(returnStmt(forFunction( - functionDecl(hasName("func12"))))))))); + EXPECT_TRUE( + matches(Code, + traverse(TK_IgnoreUnlessSpelledInSource, + declRefExpr(to(varDecl(hasName("c"))), + hasParent(returnStmt(forFunction( + functionDecl(hasName("func12"))))))), + LanguageMode::Cxx2a)); EXPECT_TRUE(matches( Code, @@ -2178,13 +2215,16 @@ void func14() { has(declRefExpr(to(varDecl(hasName("a"))))), has(varDecl(hasName("b"), hasInitializer(declRefExpr(to( varDecl(hasName("c"))))))), - has(parmVarDecl(hasName("d"))))))); + has(parmVarDecl(hasName("d"))))), + LanguageMode::Cxx2a)); - EXPECT_TRUE(matches( - Code, traverse(TK_IgnoreUnlessSpelledInSource, - declRefExpr(to(varDecl(hasName("a"))), - hasParent(lambdaExpr(forFunction( - functionDecl(hasName("func13"))))))))); + EXPECT_TRUE( + matches(Code, + traverse(TK_IgnoreUnlessSpelledInSource, + declRefExpr(to(varDecl(hasName("a"))), + hasParent(lambdaExpr(forFunction( + functionDecl(hasName("func13"))))))), + LanguageMode::Cxx2a)); EXPECT_TRUE(matches( Code, @@ -2192,18 +2232,21 @@ void func14() { varDecl(hasName("b"), hasInitializer(declRefExpr(to(varDecl(hasName("c"))))), hasParent(lambdaExpr( - forFunction(functionDecl(hasName("func13"))))))))); + forFunction(functionDecl(hasName("func13"))))))), + LanguageMode::Cxx2a)); EXPECT_TRUE(matches( - Code, traverse(TK_IgnoreUnlessSpelledInSource, - lambdaExpr( - forFunction(functionDecl(hasName("func14"))), - has(templateTypeParmDecl(hasName("TemplateType"))))))); + Code, + traverse(TK_IgnoreUnlessSpelledInSource, + lambdaExpr(forFunction(functionDecl(hasName("func14"))), + has(templateTypeParmDecl(hasName("TemplateType"))))), + LanguageMode::Cxx2a)); - EXPECT_TRUE( - matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, - functionDecl(hasName("func14"), - hasDescendant(floatLiteral()))))); + EXPECT_TRUE(matches( + Code, + traverse(TK_IgnoreUnlessSpelledInSource, + functionDecl(hasName("func14"), hasDescendant(floatLiteral()))), + LanguageMode::Cxx2a)); } TEST(IgnoringImpCasts, MatchesImpCasts) {