[Mlir-commits] [mlir] [mlir] Fix build after ec50f5828f25 (PR #101021)

Ryan Holt llvmlistbot at llvm.org
Mon Jul 29 07:37:53 PDT 2024


https://github.com/ryan-holt-1 created https://github.com/llvm/llvm-project/pull/101021

This commit fixes what appears to be invalid C++ -- a lambda capturing a variable before it is declared. The code compiles with GCC and Clang but not MSVC.

>From 8b3d1b024561e3c3711096c78761cb29a05be92f Mon Sep 17 00:00:00 2001
From: ryan-holt-1 <ryanholt at mathworks.com>
Date: Mon, 29 Jul 2024 10:29:58 -0400
Subject: [PATCH] [mlir] Fix build after ec50f5828f25

This commit fixes what appears to be invalid C++ -- a lambda capturing a
variable before it is declared. The code compiles with GCC and Clang but
not MSVC.
---
 mlir/unittests/Support/CyclicReplacerCacheTest.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/mlir/unittests/Support/CyclicReplacerCacheTest.cpp b/mlir/unittests/Support/CyclicReplacerCacheTest.cpp
index ca2eb6ce4171f..64a8ab72b69b7 100644
--- a/mlir/unittests/Support/CyclicReplacerCacheTest.cpp
+++ b/mlir/unittests/Support/CyclicReplacerCacheTest.cpp
@@ -26,14 +26,15 @@ TEST(CachedCyclicReplacerTest, testNoRecursion) {
 
 TEST(CachedCyclicReplacerTest, testInPlaceRecursionPruneAnywhere) {
   // Replacer cycles through ints 0 -> 1 -> 2 -> 0 -> ...
-  CachedCyclicReplacer<int, int> replacer(
-      /*replacer=*/[&](int n) { return replacer((n + 1) % 3); },
+  std::optional<CachedCyclicReplacer<int, int>> replacer;
+  replacer.emplace(
+      /*replacer=*/[&](int n) { return (*replacer)((n + 1) % 3); },
       /*cycleBreaker=*/[&](int n) { return -1; });
 
   // Starting at 0.
-  EXPECT_EQ(replacer(0), -1);
+  EXPECT_EQ((*replacer)(0), -1);
   // Starting at 2.
-  EXPECT_EQ(replacer(2), -1);
+  EXPECT_EQ((*replacer)(2), -1);
 }
 
 //===----------------------------------------------------------------------===//



More information about the Mlir-commits mailing list