Title
directory_iterator::increment is seemingly narrow-contract but marked noexcept
Status
resolved
Section
[fs.dir.itr.members][fs.rec.dir.itr.members]
Submitter
Tim Song

Created on 2016-12-09.00:00:00 last changed 75 months ago

Messages

Date: 2018-08-24.13:31:33

Proposed resolution:

This wording is relative to N4618.

  1. Alternative A (remove the noexcept):

    1. Edit [fs.class.directory_iterator], class directory_iterator synopsis, as indicated:

      directory_iterator& operator++();
      directory_iterator& increment(error_code& ec) noexcept;
      
    2. Edit [fs.dir.itr.members] before p10 as indicated:

      directory_iterator& operator++();
      directory_iterator& increment(error_code& ec) noexcept;
      

      -10- Effects: As specified for the prefix increment operation of Input iterators (24.2.3).

      -11- Returns: *this.

      -12- Throws: As specified in 27.10.7.

    3. Edit [fs.class.rec.dir.itr], class recursive_directory_iterator synopsis, as indicated:

      recursive_directory_iterator& operator++();
      recursive_directory_iterator& increment(error_code& ec) noexcept;
      
    4. Edit [fs.rec.dir.itr.members] before p23 as indicated:

      recursive_directory_iterator& operator++();
      recursive_directory_iterator& increment(error_code& ec) noexcept;
      

      -23- Effects: As specified for the prefix increment operation of Input iterators (24.2.3), except that: […]

      -24- Returns: *this.

      -25- Throws: As specified in 27.10.7.

  2. Alternative B (specify that increment reports an error if the iterator is not dereferenceable):

    1. Edit [fs.dir.itr.members] p10 as indicated:

      directory_iterator& operator++();
      directory_iterator& increment(error_code& ec) noexcept;
      

      -10- Effects: As specified for the prefix increment operation of Input iterators (24.2.3), except that increment reports an error if *this is not dereferenceable.

      -11- Returns: *this.

      -12- Throws: As specified in 27.10.7.

    2. Edit [fs.rec.dir.itr.members] p23 as indicated:

      recursive_directory_iterator& operator++();
      recursive_directory_iterator& increment(error_code& ec) noexcept;
      

      -23- Effects: As specified for the prefix increment operation of Input iterators (24.2.3), except that:

      • increment reports an error if *this is not dereferenceable.

      • If there are no more entries at the current depth, […]

      • Otherwise if […]

      -24- Returns: *this.

      -25- Throws: As specified in 27.10.7.

Date: 2018-08-20.00:00:00

[ 2018-08-20 Batavia Issues processing ]

Status to resolved.

Date: 2018-08-15.00:00:00

[ 2018-8-15 Offline discussions ]

Tim and Marshall recommend NAD for about Part B

Date: 2018-01-26.00:00:00

[ 2018-1-26 issues processing telecon ]

Part A is already done by 3013.

Marshall to talk to Tim about Part B; it would be odd if operator++ was undefined behaviour, but increment on the same iterator returned an error

Date: 2018-01-24.00:00:00

[ 2018-01-24 Tim Song comments ]

LWG 3013 will remove this noexcept (for a different reason). The behavior of calling increment on a nondereferenceble iterator should still be clarified, as I was informed that LWG wanted it to be well-defined.

Date: 2017-01-27.00:00:00

[ 2017-01-27 Telecon ]

Priority 2; there are some problems with the wording in alternative B.

Date: 2016-12-19.13:38:24

directory_iterator::increment and recursive_directory_iterator::increment are specified by reference to the input iterator requirements, which is narrow-contract: it has a precondition that the iterator is dereferenceable. Yet they are marked as noexcept.

Either the noexcept (one of which was added by LWG 2637) should be removed, or the behavior of increment when given a nondereferenceable iterator should be specified.

Currently, libstdc++ and MSVC report an error via the error_code argument for a nondereferenceable directory_iterator, while libc++ and boost::filesystem assert.

History
Date User Action Args
2018-08-27 14:22:44adminsetstatus: nad -> resolved
2018-08-24 13:31:33adminsetmessages: + msg10119
2018-08-24 13:31:33adminsetstatus: open -> nad
2018-08-15 14:27:58adminsetmessages: + msg10072
2018-01-28 19:43:07adminsetmessages: + msg9651
2018-01-28 19:43:07adminsetstatus: new -> open
2018-01-24 22:05:23adminsetmessages: + msg9634
2017-01-30 15:36:02adminsetmessages: + msg8816
2016-12-18 13:15:05adminsetmessages: + msg8763
2016-12-09 00:00:00admincreate