[llvm] 83887df - [ADT] Follow up to fix bug in "Add makeVisitor to STLExtras.h"

Scott Linder via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 1 11:25:16 PDT 2021


Author: Scott Linder
Date: 2021-07-01T18:24:49Z
New Revision: 83887df15597990308e9903d0480fa7676d772a1

URL: https://github.com/llvm/llvm-project/commit/83887df15597990308e9903d0480fa7676d772a1
DIFF: https://github.com/llvm/llvm-project/commit/83887df15597990308e9903d0480fa7676d772a1.diff

LOG: [ADT] Follow up to fix bug in "Add makeVisitor to STLExtras.h"

Address mistakenly comparing the pointer values of two C-style strings
rather than comparing their contents in the unit tests for makeVisitor,
added in 6d6f35eb7b92c6dd4478834497752f4e963db16d

Added: 
    

Modified: 
    llvm/unittests/ADT/STLExtrasTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/ADT/STLExtrasTest.cpp b/llvm/unittests/ADT/STLExtrasTest.cpp
index 2c2b649030880..85208e4f4a2f8 100644
--- a/llvm/unittests/ADT/STLExtrasTest.cpp
+++ b/llvm/unittests/ADT/STLExtrasTest.cpp
@@ -777,9 +777,9 @@ TEST(STLExtrasTest, MakeVisitorOneCallable) {
 
 TEST(STLExtrasTest, MakeVisitorTwoCallables) {
   auto Visitor =
-      makeVisitor([](int) { return "int"; }, [](std::string) { return "str"; });
-  EXPECT_EQ(Visitor(42), "int");
-  EXPECT_EQ(Visitor("foo"), "str");
+      makeVisitor([](int) { return 0; }, [](std::string) { return 1; });
+  EXPECT_EQ(Visitor(42), 0);
+  EXPECT_EQ(Visitor("foo"), 1);
 }
 
 TEST(STLExtrasTest, MakeVisitorCallableMultipleOperands) {
@@ -793,20 +793,20 @@ TEST(STLExtrasTest, MakeVisitorDefaultCase) {
   {
     auto Visitor = makeVisitor([](int I) { return I + 100; },
                                [](float F) { return F * 2; },
-                               [](auto) { return "unhandled type"; });
+                               [](auto) { return -1; });
     EXPECT_EQ(Visitor(24), 124);
     EXPECT_EQ(Visitor(2.f), 4.f);
-    EXPECT_EQ(Visitor(2.), "unhandled type");
-    EXPECT_EQ(Visitor(Visitor), "unhandled type");
+    EXPECT_EQ(Visitor(2.), -1);
+    EXPECT_EQ(Visitor(Visitor), -1);
   }
   {
-    auto Visitor = makeVisitor([](auto) { return "unhandled type"; },
+    auto Visitor = makeVisitor([](auto) { return -1; },
                                [](int I) { return I + 100; },
                                [](float F) { return F * 2; });
     EXPECT_EQ(Visitor(24), 124);
     EXPECT_EQ(Visitor(2.f), 4.f);
-    EXPECT_EQ(Visitor(2.), "unhandled type");
-    EXPECT_EQ(Visitor(Visitor), "unhandled type");
+    EXPECT_EQ(Visitor(2.), -1);
+    EXPECT_EQ(Visitor(Visitor), -1);
   }
 }
 


        


More information about the llvm-commits mailing list