Branch: refs/heads/main Home: https://github.com/WebKit/WebKit Commit: 460abf576622806c66767e3ac5c9f01ee912070e https://github.com/WebKit/WebKit/commit/460abf576622806c66767e3ac5c9f01ee912070e Author: Geoffrey Garen <gga...@apple.com> Date: 2024-11-03 (Sun, 03 Nov 2024)
Changed paths: M Source/WTF/wtf/IndexedRange.h Log Message: ----------- IndexedRange is unsafe to use with temporaries https://bugs.webkit.org/show_bug.cgi?id=282503 rdar://139127354 Reviewed by Mike Wyrzykowski and Chris Dumez. This was technically undef: for (auto [ index, value ] : IndexedRange(std::span(collection))) { ... } because IndexedRange kept a reference to its constructor argument, which was a destroyed temporary. The solution has three parts: 1. Use an IndexedRange(Collection&&) overload to detect construction with a temporary. 2. Store begin() / end() iterators instead of a reference to the collection. This eliminates the reference to a destroyed temporary -- but adds use of an iterator after invalidation. Yayboo. 3. static_assert that the temporary supports std::ranges::borrowed_range, which makes use of an iterator after invalidation well-defined. Yay. * Source/WTF/wtf/IndexedRange.h: (WTF::IndexedRange::IndexedRange): (WTF::IndexedRange::begin): (WTF::IndexedRange::end): Canonical link: https://commits.webkit.org/286060@main To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications _______________________________________________ webkit-changes mailing list webkit-changes@lists.webkit.org https://lists.webkit.org/mailman/listinfo/webkit-changes