Skip to content

Commit 197d619

Browse files
committed
Fix C++17 compatibility: avoid capturing structured bindings in lambdas
Structured bindings cannot be captured in lambdas in C++17 (only C++20+). Changed llvm::zip loops to llvm::enumerate and extract actionName separately to avoid capturing structured bindings inside nested lambdas. Fixes CI build error on Ubuntu 22.04 with clang 14.
1 parent 16d9f82 commit 197d619

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/Transforms/SwitchElimination.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,14 @@ LogicalResult SwitchEliminationPass::eliminateSwitch(P4HIR::ControlOp control,
160160
tableBuilder.create<P4HIR::TableEntriesOp>(
161161
tableLoc, true, DictionaryAttr(),
162162
[&](OpBuilder &b, Location entriesLoc) {
163-
for (auto [caseOp, actionName] : llvm::zip(cases, llvm::ArrayRef(actionNames).drop_back())) {
163+
for (auto enumItem : llvm::enumerate(cases)) {
164+
size_t i = enumItem.index();
165+
P4HIR::CaseOp caseOp = enumItem.value();
166+
auto actionName = actionNames[i];
164167
for (auto valueAttr : caseOp.getValue()) {
165168
auto tupleType = TupleType::get(ctx, {condType});
166169
auto keyAttr = P4HIR::AggAttr::get(
167-
tupleType, b.getArrayAttr({valueAttr}));
170+
tupleType, b.getArrayAttr({valueAttr}));
168171
b.create<P4HIR::TableEntryOp>(
169172
entriesLoc, keyAttr, false, TypedAttr(), DictionaryAttr(),
170173
[&](OpBuilder &entryBuilder, Location entryLoc) {
@@ -203,7 +206,10 @@ LogicalResult SwitchEliminationPass::eliminateSwitch(P4HIR::ControlOp control,
203206
(void)builder.create<P4HIR::SwitchOp>(
204207
loc, actionRunField.getResult(),
205208
[&](OpBuilder &switchBuilder, Location switchLoc) {
206-
for (auto [caseOp, actionName] : llvm::zip(cases, llvm::ArrayRef(actionNames).drop_back())) {
209+
for (auto enumItem : llvm::enumerate(cases)) {
210+
size_t i = enumItem.index();
211+
P4HIR::CaseOp caseOp = enumItem.value();
212+
auto actionName = actionNames[i];
207213
auto enumMemberAttr = P4HIR::EnumFieldAttr::get(actionEnumType, actionName);
208214
switchBuilder.create<P4HIR::CaseOp>(
209215
switchLoc, switchBuilder.getArrayAttr({enumMemberAttr}),

0 commit comments

Comments
 (0)