Files
2025-10-25 03:02:53 +03:00

1.1 KiB

[diff.cpp20.stmt]

Annex C (informative) Compatibility [diff]

C.2 C++ and ISO C++ 2020 [diff.cpp20]

C.2.4 [stmt]: statements [diff.cpp20.stmt]

1

#

Affected subclause: [stmt.ranged]

Change: The lifetime of temporary objects in the for-range-initializer is extended until the end of the loop ([class.temporary]).

Rationale: Improve usability of the range-based for statement.

Effect on original feature: Destructors of some temporary objects are invoked later.

[Example 1: void f() { std::vector v = { 42, 17, 13 }; std::mutex m; for (int x :static_cast(std::lock_guardstd::mutex(m)), v) { // lock released in C++ 2020 std::lock_guardstd::mutex guard(m); // OK in C++ 2020, now deadlocks}} — end example]