[PATCH] D107378: Make enum iteration with seq safe by default

Jakub Kuderski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 7 13:07:21 PDT 2021


kuhar marked 2 inline comments as done.
kuhar added a comment.

In D107378#2987127 <https://reviews.llvm.org/D107378#2987127>, @dblaikie wrote:

> Do you/we have a use for this machinery in mind? (especially the extra `forge` pieces - probably nice to leave that out until/unless it's needed - maybe even if it is needed, might be easier to review separately/in a follow-up patch)

This works with the existing code by making iteration over enum values safe by considering enums unsafe to iterate over unless opted in. `forge_iterable_enum` is used as an escape hatch to opt into unsafe iteration when it makes sense at a given callsite, e.g., when only some subset of values is safe to iterate over, or when it's not possible/easy to provide traits next to the enum definition. I used `forge_iterable_enum` with `X86::CondCode` in this patch.



================
Comment at: llvm/unittests/ADT/SequenceTest.cpp:236
+  EXPECT_TRUE(llvm::empty(
+      llvm::iota_range<UntypedEnum>(UntypedEnum::A, UntypedEnum::A, false)));
+  EXPECT_THAT(
----------------
gchatelet wrote:
> You shouldn't need to qualify the template argument here and below. This would help readability.
> You shouldn't need to qualify the template argument here and below. This would help readability.

This seems required in c++14. `iota_range` is a class template, not a function template.




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107378/new/

https://reviews.llvm.org/D107378



More information about the llvm-commits mailing list