Title
Problematic specification of the wide version of basic_filebuf::open
Status
c++20
Section
[filebuf.members]
Submitter
Tim Song

Created on 2017-03-09.00:00:00 last changed 46 months ago

Messages

Date: 2018-11-12.04:39:29

Proposed resolution:

This wording is relative to N4713.

  1. Edit [filebuf.members] as indicated:

    basic_filebuf* open(const char* s, ios_base::openmode mode);
    basic_filebuf* open(const filesystem::path::value_type* s,
                        ios_base::openmode mode); // wide systems only; see [fstream.syn]
    

    -?- Expects: s shall point to a NTCTS ([defns.ntcts]).

    -2- Effects: If is_open() != false, returns a null pointer. Otherwise, initializes the filebuf as required. It then opens the file to which s resolves, if possible, as if by a call to fopen with the second argumenta file, if possible, whose name is the ntbs s (as if by calling fopen(s, modstr)). The ntbs modstr is determined from mode & ~ios_base::ate as indicated in Table 117. If mode is not some combination of flags shown in the table then the open fails.

    -3- If the open operation succeeds and (mode & ios_base::ate) != 0, positions the file to the end (as if by calling fseek(file, 0, SEEK_END), where file is the pointer returned by calling fopen).(footnote 330)

    -4- If the repositioning operation fails, calls close() and returns a null pointer to indicate failure.

    -5- Returns: this if successful, a null pointer otherwise.

Date: 2018-11-12.04:39:29

[ 2018-11, Adopted in San Diego ]

Date: 2018-08-23.00:00:00

[ 2018-08-23 Batavia Issues processing ]

Adopted after changing 'Requires' -> 'Expects' in the P/R.

Date: 2018-08-15.00:00:00

[ 2018-08-14; Marshall corrects a grammar nit in the P/R ]

The Microsoft guys note that "as by a call to fopen" is OK by them.

Previous resolution [SUPERSEDED]:

This wording is relative to N4713.

  1. Edit [filebuf.members] as indicated:

    basic_filebuf* open(const char* s, ios_base::openmode mode);
    basic_filebuf* open(const filesystem::path::value_type* s,
                        ios_base::openmode mode); // wide systems only; see [fstream.syn]
    

    -?- Requires: s shall point to a NTCTS ([defns.ntcts]).

    -2- Effects: If is_open() != false, returns a null pointer. Otherwise, initializes the filebuf as required. It then opens the file to which s resolves, if possible, as if by a call to fopen with the second argumenta file, if possible, whose name is the ntbs s (as if by calling fopen(s, modstr)). The ntbs modstr is determined from mode & ~ios_base::ate as indicated in Table 117. If mode is not some combination of flags shown in the table then the open fails.

    -3- If the open operation succeeds and (mode & ios_base::ate) != 0, positions the file to the end (as if by calling fseek(file, 0, SEEK_END), where file is the pointer returned by calling fopen).(footnote 330)

    -4- If the repositioning operation fails, calls close() and returns a null pointer to indicate failure.

    -5- Returns: this if successful, a null pointer otherwise.

Date: 2018-01-15.00:00:00

[ 2018-01-16; Jonathan and Tim Song provide wording ]

We'll have to ask the Microsoft guys if "as by a call to fopen" is OK for them. There are paths that can be represented as a wide character string that can't reliably be converted to narrow characters (because they become dependent on the current codepage, or some other Windows nonsense) so they definitely won't use fopen. But as long as they call something that behaves like it (which should allow _fwopen), I think they'll still meet the spirit of the wording.

Date: 2017-11-10.03:05:33

[ 2017-11 Albuquerque Wednesday issue processing ]

Status to Open; Jonathan to provide wording.

Date: 2017-07-15.22:58:07

[ 2017-07 Toronto Wed Issue Prioritization ]

Priority 2

Date: 2017-03-09.00:00:00

LWG 2676 specified basic_filebuf::open(const std::filesystem::path::value_type* s, ios_base::openmode mode) by simply reusing the specification for the const char* overload, but that specification is incorrect for the wide overload: it says that s is an NTBS — a null-terminated byte string — which it isn't. Moreover, it specifies that the file is opened as if by calling fopen(s, modstr), but that call is ill-formed if s isn't a const char*.

History
Date User Action Args
2021-02-25 10:48:01adminsetstatus: wp -> c++20
2018-11-12 04:39:29adminsetmessages: + msg10182
2018-11-12 04:39:29adminsetstatus: voting -> wp
2018-10-08 05:13:59adminsetstatus: ready -> voting
2018-08-24 13:31:33adminsetmessages: + msg10120
2018-08-24 13:31:33adminsetstatus: open -> ready
2018-08-15 14:22:09adminsetmessages: + msg10070
2018-01-20 16:23:20adminsetmessages: + msg9616
2018-01-20 16:23:20adminsetmessages: + msg9615
2017-11-10 03:05:33adminsetmessages: + msg9538
2017-11-10 03:05:33adminsetstatus: new -> open
2017-07-15 22:58:07adminsetmessages: + msg9373
2017-03-09 00:00:00admincreate