From Jason Turner

[diff.cpp20.stmt]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpm8bsitl6/{from.md → to.md} +20 -0
tmp/tmpm8bsitl6/{from.md → to.md} RENAMED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### [[stmt.stmt]]: statements <a id="diff.cpp20.stmt">[[diff.cpp20.stmt]]</a>
2
+
3
+ **Change:** The lifetime of temporary objects in the
4
+ *for-range-initializer* is extended until the end of the loop
5
+ [[class.temporary]]. **Rationale:** Improve usability of the range-based
6
+ `for` statement. **Effect on original feature:** Destructors of some
7
+ temporary objects are invoked later. For example:
8
+
9
+ ``` cpp
10
+ void f() {
11
+ std::vector<int> v = { 42, 17, 13 };
12
+ std::mutex m;
13
+
14
+ for (int x :
15
+ static_cast<void>(std::lock_guard<std::mutex>(m)), v) { // lock released in C++20
16
+ std::lock_guard<std::mutex> guard(m); // OK in C++20, now deadlocks
17
+ }
18
+ }
19
+ ```
20
+