Title
Lifetime of temporaries in range-based for
Status
dup
Section
8.6.5 [stmt.ranged]
Submitter
Beman Dawes

Created on 2012-04-26.00:00:00 last changed 147 months ago

Messages

Date: 2012-10-15.00:00:00

Rationale (October, 2012):

This is a duplicate of issue 900.

Date: 2022-11-20.07:54:16

Because the reference __range in the expansion of a range-based for statement, as described in 8.6.5 [stmt.ranged] paragraph 1, is bound only to the top-level expression of range-init, the lifetime of temporaries created at lower levels in that expression expires before the body of the loop is reached, leading to dangling references. It would be helpful if the lifetime of those temporaries were extended over the entire statement.

(See also issue 1523 for another question regarding the rewritten form of the range-based for.)

History
Date User Action Args
2012-11-03 00:00:00adminsetmessages: + msg4185
2012-11-03 00:00:00adminsetstatus: open -> dup
2012-04-26 00:00:00admincreate