This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++17 status.

2672. Should is_empty use error_code in its specification?

Section: 31.12.13.20 [fs.op.is.empty] Status: C++17 Submitter: Jonathan Wakely Opened: 2014-08-01 Last modified: 2021-06-06

Priority: 3

View all issues with C++17 status.

Discussion:

The descriptions of most functions are explicit about the use of the ec argument, either saying something like "foo(p) or foo(p, ec), respectively" or using the ec argument like foo(p[, ec]), but is_empty does not.

[fs.op.is_empty]/2 refers to ec unconditionally, but more importantly [fs.op.is_empty]/3 doesn't pass ec to the directory_iterator constructor or the file_size function.

[ 9 Oct 2014 Beman supplies proposed wording. ]

[Apr 2016 Issue updated to address the C++ Working Paper. Previously addressed File System TS]

Previous resolution [SUPERSEDED]:

  1.     bool is_empty(const path& p);
        bool is_empty(const path& p, error_code& ec) noexcept;
      

    Effects:

    • Determine file_status s, as if by status(p) or status(p, ec), respectively.
    • For the signature with argument ec, return false if an error occurred.
    • Otherwise, if is_directory(s):
      • Create directory_iterator itr, as if by directory_iterator(p) or directory_iterator(p, ec), respectively.
      • For the signature with argument ec, return false if an error occurred.
      • Otherwise, return itr == directory_iterator().
    • Otherwise:
      • Determine uintmax_t sz, as if by file_size(p) or file_size(p, ec), respectively .
      • For the signature with argument ec, return false if an error occurred.
      • Otherwise, return sz == 0.

    Remarks: The temporary objects described in Effects are for exposition only. Implementations are not required to create them.

    Returns: is_directory(s) ? directory_iterator(p) == directory_iterator() : file_size(p) == 0; See Effects.

    The signature with argument ec returns false if an error occurs.

    Throws: As specified in Error reporting (7).

[2016-08 Chicago]

Wed PM: Move to Tentatively Ready

Proposed resolution:

  1.     bool is_empty(const path& p);
        bool is_empty(const path& p, error_code& ec) noexcept;
      

    Effects:

    • Determine file_status s, as if by status(p) or status(p, ec), respectively.
    • For the signature with argument ec, return false if an error occurred.
    • Otherwise, if is_directory(s):
      • Create directory_iterator itr, as if by directory_iterator(p) or directory_iterator(p, ec), respectively.
      • For the signature with argument ec, return false if an error occurred.
      • Otherwise, return itr == directory_iterator().
    • Otherwise:
      • Determine uintmax_t sz, as if by file_size(p) or file_size(p, ec), respectively .
      • For the signature with argument ec, return false if an error occurred.
      • Otherwise, return sz == 0.

    Returns: is_directory(s) ? directory_iterator(p) == directory_iterator() : file_size(p) == 0;

    The signature with argument ec returns false if an error occurs.

    Throws: As specified in Error reporting (7).