diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2014-02-26 10:23:43 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2014-02-26 10:23:43 +0000 |
commit | 594802f7447e5fccd15b489dadb886719dc24012 (patch) | |
tree | b0932f5628d86cdfd264bc3162b34fe600c33180 /clang/unittests/AST/StmtPrinterTest.cpp | |
parent | bd25bebf75736c0692f64f26c8119d62b8c9393d (diff) | |
download | bcm5719-llvm-594802f7447e5fccd15b489dadb886719dc24012.tar.gz bcm5719-llvm-594802f7447e5fccd15b489dadb886719dc24012.zip |
Add a StmtPrinter test for implicit and explicit conversion operator calls.
Put back a comment that I removed too aggressively.
llvm-svn: 202255
Diffstat (limited to 'clang/unittests/AST/StmtPrinterTest.cpp')
-rw-r--r-- | clang/unittests/AST/StmtPrinterTest.cpp | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/clang/unittests/AST/StmtPrinterTest.cpp b/clang/unittests/AST/StmtPrinterTest.cpp index eac36d65ee4..5f54abd0c0b 100644 --- a/clang/unittests/AST/StmtPrinterTest.cpp +++ b/clang/unittests/AST/StmtPrinterTest.cpp @@ -64,11 +64,10 @@ public: } }; -::testing::AssertionResult PrintedStmtMatches( - StringRef Code, - const std::vector<std::string> &Args, - const DeclarationMatcher &NodeMatch, - StringRef ExpectedPrinted) { +template <typename T> +::testing::AssertionResult +PrintedStmtMatches(StringRef Code, const std::vector<std::string> &Args, + const T &NodeMatch, StringRef ExpectedPrinted) { PrintMatch Printer; MatchFinder Finder; @@ -96,6 +95,15 @@ public: return ::testing::AssertionSuccess(); } +::testing::AssertionResult +PrintedStmtCXX98Matches(StringRef Code, const StatementMatcher &NodeMatch, + StringRef ExpectedPrinted) { + std::vector<std::string> Args; + Args.push_back("-std=c++98"); + Args.push_back("-Wno-unused-value"); + return PrintedStmtMatches(Code, Args, NodeMatch, ExpectedPrinted); +} + ::testing::AssertionResult PrintedStmtCXX98Matches( StringRef Code, StringRef ContainingFunction, @@ -110,6 +118,15 @@ public: ExpectedPrinted); } +::testing::AssertionResult +PrintedStmtCXX11Matches(StringRef Code, const StatementMatcher &NodeMatch, + StringRef ExpectedPrinted) { + std::vector<std::string> Args; + Args.push_back("-std=c++11"); + Args.push_back("-Wno-unused-value"); + return PrintedStmtMatches(Code, Args, NodeMatch, ExpectedPrinted); +} + ::testing::AssertionResult PrintedStmtMSMatches( StringRef Code, StringRef ContainingFunction, @@ -164,3 +181,32 @@ TEST(StmtPrinter, TestFloatingPointLiteral) { "1.F , -1.F , 1. , -1. , 1.L , -1.L")); // Should be: with semicolon } + +TEST(StmtPrinter, TestCXXConversionDeclImplicit) { + ASSERT_TRUE(PrintedStmtCXX98Matches( + "struct A {" + "operator void *();" + "A operator&(A);" + "};" + "void bar(void *);" + "void foo(A a, A b) {" + " bar(a & b);" + "}", + memberCallExpr(anything()).bind("id"), + "a & b")); +} + +TEST(StmtPrinter, TestCXXConversionDeclExplicit) { + ASSERT_TRUE(PrintedStmtCXX11Matches( + "struct A {" + "operator void *();" + "A operator&(A);" + "};" + "void bar(void *);" + "void foo(A a, A b) {" + " auto x = (a & b).operator void *();" + "}", + memberCallExpr(anything()).bind("id"), + "(a & b)")); + // WRONG; Should be: (a & b).operator void *() +} |