balazske updated this revision to Diff 149079.
balazske added a comment.
[ASTImporter] Fixed test code in ASTImporter tests.
Test code is fixed instead of turn off the warnings.
For this to work change of match expressions was needed.
Repository:
rC Clang
https://reviews.llvm.org/D47459
Files:
unittests/AST/ASTImporterTest.cpp
Index: unittests/AST/ASTImporterTest.cpp
===================================================================
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -427,117 +427,99 @@
TEST(ImportExpr, ImportStringLiteral) {
MatchVerifier<Decl> Verifier;
- testImport("void declToImport() { \"foo\"; }",
+ testImport("void declToImport() { (void)\"foo\"; }",
Lang_CXX, "", Lang_CXX, Verifier,
functionDecl(
- hasBody(
- compoundStmt(
- has(
- stringLiteral(
- hasType(
- asString("const char [4]"))))))));
- testImport("void declToImport() { L\"foo\"; }",
+ hasDescendant(
+ stringLiteral(
+ hasType(
+ asString("const char [4]"))))));
+ testImport("void declToImport() { (void)L\"foo\"; }",
Lang_CXX, "", Lang_CXX, Verifier,
functionDecl(
- hasBody(
- compoundStmt(
- has(
- stringLiteral(
- hasType(
- asString("const wchar_t [4]"))))))));
- testImport("void declToImport() { \"foo\" \"bar\"; }",
+ hasDescendant(
+ stringLiteral(
+ hasType(
+ asString("const wchar_t [4]"))))));
+ testImport("void declToImport() { (void) \"foo\" \"bar\"; }",
Lang_CXX, "", Lang_CXX, Verifier,
functionDecl(
- hasBody(
- compoundStmt(
- has(
- stringLiteral(
- hasType(
- asString("const char [7]"))))))));
+ hasDescendant(
+ stringLiteral(
+ hasType(
+ asString("const char [7]"))))));
}
TEST(ImportExpr, ImportGNUNullExpr) {
MatchVerifier<Decl> Verifier;
- testImport("void declToImport() { __null; }",
+ testImport("void declToImport() { (void)__null; }",
Lang_CXX, "", Lang_CXX, Verifier,
functionDecl(
- hasBody(
- compoundStmt(
- has(
- gnuNullExpr(
- hasType(isInteger())))))));
+ hasDescendant(
+ gnuNullExpr(
+ hasType(isInteger())))));
}
TEST(ImportExpr, ImportCXXNullPtrLiteralExpr) {
MatchVerifier<Decl> Verifier;
- testImport("void declToImport() { nullptr; }",
+ testImport("void declToImport() { (void)nullptr; }",
Lang_CXX11, "", Lang_CXX11, Verifier,
functionDecl(
- hasBody(
- compoundStmt(
- has(
- cxxNullPtrLiteralExpr())))));
+ hasDescendant(
+ cxxNullPtrLiteralExpr())));
}
TEST(ImportExpr, ImportFloatinglLiteralExpr) {
MatchVerifier<Decl> Verifier;
- testImport("void declToImport() { 1.0; }",
+ testImport("void declToImport() { (void)1.0; }",
Lang_C, "", Lang_C, Verifier,
functionDecl(
- hasBody(
- compoundStmt(
- has(
- floatLiteral(
- equals(1.0),
- hasType(asString("double"))))))));
- testImport("void declToImport() { 1.0e-5f; }",
+ hasDescendant(
+ floatLiteral(
+ equals(1.0),
+ hasType(asString("double"))))));
+ testImport("void declToImport() { (void)1.0e-5f; }",
Lang_C, "", Lang_C, Verifier,
functionDecl(
- hasBody(
- compoundStmt(
- has(
- floatLiteral(
- equals(1.0e-5f),
- hasType(asString("float"))))))));
+ hasDescendant(
+ floatLiteral(
+ equals(1.0e-5f),
+ hasType(asString("float"))))));
}
TEST(ImportExpr, ImportCompoundLiteralExpr) {
MatchVerifier<Decl> Verifier;
testImport("void declToImport() {"
" struct s { int x; long y; unsigned z; }; "
- " (struct s){ 42, 0L, 1U }; }",
+ " (void) (struct s){ 42, 0L, 1U }; }",
Lang_CXX, "", Lang_CXX, Verifier,
functionDecl(
- hasBody(
- compoundStmt(
- has(
- compoundLiteralExpr(
- hasType(asString("struct s")),
- has(initListExpr(
- hasType(asString("struct s")),
- has(integerLiteral(
- equals(42), hasType(asString("int")))),
- has(integerLiteral(
- equals(0), hasType(asString("long")))),
- has(integerLiteral(
- equals(1),
- hasType(asString("unsigned int"))))
- ))))))));
+ hasDescendant(
+ compoundLiteralExpr(
+ hasType(asString("struct s")),
+ has(initListExpr(
+ hasType(asString("struct s")),
+ has(integerLiteral(
+ equals(42), hasType(asString("int")))),
+ has(integerLiteral(
+ equals(0), hasType(asString("long")))),
+ has(integerLiteral(
+ equals(1),
+ hasType(asString("unsigned int"))))
+ ))))));
}
TEST(ImportExpr, ImportCXXThisExpr) {
MatchVerifier<Decl> Verifier;
- testImport("class declToImport { void f() { this; } };",
+ testImport("class declToImport { void f() { (void)this; } };",
Lang_CXX, "", Lang_CXX, Verifier,
cxxRecordDecl(
hasMethod(
- hasBody(
- compoundStmt(
- has(
- cxxThisExpr(
- hasType(
- asString("class declToImport *")))))))));
+ hasDescendant(
+ cxxThisExpr(
+ hasType(
+ asString("class declToImport *")))))));
}
TEST(ImportExpr, ImportAtomicExpr) {
@@ -554,11 +536,16 @@
TEST(ImportExpr, ImportLabelDeclAndAddrLabelExpr) {
MatchVerifier<Decl> Verifier;
testImport(
- "void declToImport() { loop: goto loop; &&loop; }", Lang_C, "", Lang_C,
- Verifier,
- functionDecl(hasBody(compoundStmt(
+ "void declToImport() { loop: goto loop; (void)&&loop; }",
+ Lang_C, "", Lang_C, Verifier,
+ /*functionDecl(hasBody(compoundStmt(
has(labelStmt(hasDeclaration(labelDecl(hasName("loop"))))),
- has(addrLabelExpr(hasDeclaration(labelDecl(hasName("loop")))))))));
+ has(addrLabelExpr(hasDeclaration(labelDecl(hasName("loop")))))))));*/
+ functionDecl(
+ hasDescendant(
+ labelStmt(hasDeclaration(labelDecl(hasName("loop"))))),
+ hasDescendant(
+ addrLabelExpr(hasDeclaration(labelDecl(hasName("loop")))))));
}
AST_MATCHER_P(TemplateDecl, hasTemplateDecl,
@@ -625,42 +612,38 @@
TEST(ImportExpr, ImportConditionalOperator) {
MatchVerifier<Decl> Verifier;
testImport(
- "void declToImport() { true ? 1 : -5; }",
+ "void declToImport() { (void) (true ? 1 : -5); }",
Lang_CXX, "", Lang_CXX, Verifier,
functionDecl(
- hasBody(
- compoundStmt(
- has(
- conditionalOperator(
- hasCondition(cxxBoolLiteral(equals(true))),
- hasTrueExpression(integerLiteral(equals(1))),
- hasFalseExpression(
- unaryOperator(hasUnaryOperand(integerLiteral(equals(5))))
- )))))));
+ hasDescendant(
+ conditionalOperator(
+ hasCondition(cxxBoolLiteral(equals(true))),
+ hasTrueExpression(integerLiteral(equals(1))),
+ hasFalseExpression(
+ unaryOperator(hasUnaryOperand(integerLiteral(equals(5)))))))));
}
TEST(ImportExpr, ImportBinaryConditionalOperator) {
MatchVerifier<Decl> Verifier;
testImport(
- "void declToImport() { 1 ?: -5; }", Lang_CXX, "", Lang_CXX, Verifier,
+ "void declToImport() { (void) (1 ?: -5); }",
+ Lang_CXX, "", Lang_CXX, Verifier,
functionDecl(
- hasBody(
- compoundStmt(
- has(
- binaryConditionalOperator(
- hasCondition(
- implicitCastExpr(
- hasSourceExpression(
- opaqueValueExpr(
- hasSourceExpression(integerLiteral(equals(1))))),
- hasType(booleanType()))),
- hasTrueExpression(
- opaqueValueExpr(hasSourceExpression(
- integerLiteral(equals(1))))),
- hasFalseExpression(
- unaryOperator(hasOperatorName("-"),
- hasUnaryOperand(integerLiteral(equals(5)))))
- ))))));
+ hasDescendant(
+ binaryConditionalOperator(
+ hasCondition(
+ implicitCastExpr(
+ hasSourceExpression(
+ opaqueValueExpr(
+ hasSourceExpression(integerLiteral(equals(1))))),
+ hasType(booleanType()))),
+ hasTrueExpression(
+ opaqueValueExpr(hasSourceExpression(
+ integerLiteral(equals(1))))),
+ hasFalseExpression(
+ unaryOperator(hasOperatorName("-"),
+ hasUnaryOperand(integerLiteral(equals(5)))))
+ ))));
}
TEST(ImportExpr, ImportDesignatedInitExpr) {
@@ -709,19 +692,17 @@
TEST(ImportExpr, ImportPredefinedExpr) {
MatchVerifier<Decl> Verifier;
// __func__ expands as StringLiteral("declToImport")
- testImport("void declToImport() { __func__; }",
+ testImport("void declToImport() { (void)__func__; }",
Lang_CXX, "", Lang_CXX, Verifier,
functionDecl(
- hasBody(
- compoundStmt(
+ hasDescendant(
+ predefinedExpr(
+ hasType(
+ asString("const char [13]")),
has(
- predefinedExpr(
+ stringLiteral(
hasType(
- asString("const char [13]")),
- has(
- stringLiteral(
- hasType(
- asString("const char [13]"))))))))));
+ asString("const char [13]"))))))));
}
TEST(ImportExpr, ImportInitListExpr) {
@@ -814,21 +795,23 @@
testImport("template <typename T> struct C { T t; };"
"template <typename T> void declToImport() {"
" C<T> d;"
- " d.t;"
+ " (void)d.t;"
"}"
"void instantiate() { declToImport<int>(); }",
Lang_CXX, "", Lang_CXX, Verifier,
- functionTemplateDecl(has(functionDecl(
- has(compoundStmt(has(cxxDependentScopeMemberExpr())))))));
+ functionTemplateDecl(has(functionDecl(has(compoundStmt(has(
+ cStyleCastExpr(has(
+ cxxDependentScopeMemberExpr())))))))));
testImport("template <typename T> struct C { T t; };"
"template <typename T> void declToImport() {"
" C<T> d;"
- " (&d)->t;"
+ " (void)(&d)->t;"
"}"
"void instantiate() { declToImport<int>(); }",
Lang_CXX, "", Lang_CXX, Verifier,
- functionTemplateDecl(has(functionDecl(
- has(compoundStmt(has(cxxDependentScopeMemberExpr())))))));
+ functionTemplateDecl(has(functionDecl(has(compoundStmt(has(
+ cStyleCastExpr(has(
+ cxxDependentScopeMemberExpr())))))))));
}
TEST(ImportType, ImportTypeAliasTemplate) {
@@ -853,10 +836,10 @@
testImport(
"template <typename T>"
"T pi = T(3.1415926535897932385L);"
- "void declToImport() { pi<int>; }",
- Lang_CXX11, "", Lang_CXX11, Verifier,
+ "void declToImport() { (void) pi<int>; }",
+ Lang_CXX14, "", Lang_CXX14, Verifier,
functionDecl(
- hasBody(has(declRefExpr(to(varTemplateSpecializationDecl())))),
+ hasDescendant(declRefExpr(to(varTemplateSpecializationDecl()))),
unless(hasAncestor(translationUnitDecl(has(varDecl(
hasName("pi"), unless(varTemplateSpecializationDecl()))))))));
}
@@ -937,14 +920,12 @@
TEST(ImportExpr, ImportTypeTraitExpr) {
MatchVerifier<Decl> Verifier;
testImport("void declToImport() { "
- " __builtin_types_compatible_p(int, int);"
+ " (void)__builtin_types_compatible_p(int, int);"
"}",
Lang_C, "", Lang_C, Verifier,
functionDecl(
- hasBody(
- compoundStmt(
- has(
- typeTraitExpr(hasType(asString("int"))))))));
+ hasDescendant(
+ typeTraitExpr(hasType(asString("int"))))));
}
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTypeidExpr> cxxTypeidExpr;
@@ -968,21 +949,19 @@
TEST(ImportExpr, ImportTypeTraitExprValDep) {
MatchVerifier<Decl> Verifier;
testImport("template<typename T> struct declToImport {"
- " void m() { __is_pod(T); }"
+ " void m() { (void)__is_pod(T); }"
"};"
"void f() { declToImport<int>().m(); }",
Lang_CXX11, "", Lang_CXX11, Verifier,
classTemplateDecl(
has(
cxxRecordDecl(
has(
functionDecl(
- hasBody(
- compoundStmt(
- has(
- typeTraitExpr(
- hasType(booleanType())
- ))))))))));
+ hasDescendant(
+ typeTraitExpr(
+ hasType(booleanType())
+ ))))))));
}
const internal::VariadicDynCastAllOfMatcher<Expr, CXXPseudoDestructorExpr>
@@ -1039,13 +1018,13 @@
MatchVerifier<Decl> Verifier;
testImport("template<typename T> int foo();"
"template <typename T> void declToImport() {"
- " ::foo<T>;"
- " ::template foo<T>;"
+ " (void) ::foo<T>;"
+ " (void) ::template foo<T>;"
"}"
"void instantiate() { declToImport<int>(); }",
Lang_CXX, "", Lang_CXX, Verifier,
functionTemplateDecl(has(functionDecl(
- has(compoundStmt(has(unresolvedLookupExpr())))))));
+ hasDescendant(unresolvedLookupExpr())))));
}
TEST(ImportExpr, ImportCXXUnresolvedConstructExpr) {
@@ -1850,7 +1829,8 @@
"template <typename T> void declToImport() {"
" (void) S<T>::foo;"
"}"
- "void instantiate() { declToImport<int>(); }",
+ "void instantiate() { declToImport<int>(); }"
+ "template <typename T> T S<T>::foo;",
Lang_CXX11, "", Lang_CXX11, Verifier,
functionTemplateDecl(has(functionDecl(has(compoundStmt(
has(cStyleCastExpr(has(dependentScopeDeclRefExpr())))))))));
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits