r202255 - Add a StmtPrinter test for implicit and explicit conversion operator calls.

Benjamin Kramer benny.kra at googlemail.com
Wed Feb 26 02:23:44 PST 2014


Author: d0k
Date: Wed Feb 26 04:23:43 2014
New Revision: 202255

URL: http://llvm.org/viewvc/llvm-project?rev=202255&view=rev
Log:
Add a StmtPrinter test for implicit and explicit conversion operator calls.

Put back a comment that I removed too aggressively.

Modified:
    cfe/trunk/unittests/AST/DeclPrinterTest.cpp
    cfe/trunk/unittests/AST/StmtPrinterTest.cpp

Modified: cfe/trunk/unittests/AST/DeclPrinterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/DeclPrinterTest.cpp?rev=202255&r1=202254&r2=202255&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/DeclPrinterTest.cpp (original)
+++ cfe/trunk/unittests/AST/DeclPrinterTest.cpp Wed Feb 26 04:23:43 2014
@@ -519,6 +519,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl
     "};",
     constructorDecl(ofClass(hasName("A"))).bind("id"),
     "A<T...>(T &&ts...) : T(ts)..."));
+    // WRONG; Should be: "A(T&&... ts) : T(ts)..."
 }
 
 TEST(DeclPrinter, TestCXXDestructorDecl1) {

Modified: cfe/trunk/unittests/AST/StmtPrinterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/StmtPrinterTest.cpp?rev=202255&r1=202254&r2=202255&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/StmtPrinterTest.cpp (original)
+++ cfe/trunk/unittests/AST/StmtPrinterTest.cpp Wed Feb 26 04:23:43 2014
@@ -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, TestFloatingPointLiter
     "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 *()
+}





More information about the cfe-commits mailing list