Issue Details (XML | Word | Printable)

Key: STDCXX-319
Type: Bug Bug
Status: Open Open
Priority: Trivial Trivial
Assignee: Martin Sebor
Reporter: Martin Sebor
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
C++ Standard Library

[LWG #596] std::filebuf::open(..., ios::app) unexpectedly succeeds

Created: 16/Jan/07 07:05 PM   Updated: 18/Mar/08 04:23 PM
Return to search
Component/s: 27. Input/Output
Affects Version/s: 4.1.2, 4.1.3
Fix Version/s: 4.3.0

Time Tracking:
Original Estimate: 2h
Original Estimate - 2h
Remaining Estimate: 2h
Remaining Estimate - 2h
Time Spent: Not Specified
Remaining Estimate - 2h

Environment: all

Severity: Incorrect Behavior


 Description  « Hide
According to filebuf.members, p2, filebuf::open(const char*, openmode mode) is not some combination of the flags listed in Table 113 the call is supposed to fail. Since ios::app only appears in conjunction with ios::out (and ios::binary|ios::out) the call in the program below should fail.

$ cat t.cpp && make t && ./t
#include <cassert>
#include <fstream>

int main ()
{
std::filebuf fb;

const std::filebuf* const pfb = fb.open ("dummy", std::ios::app);

assert (0 == pfb);
}
gcc -c -I/build/sebor/dev/stdlib/include/ansi -D_RWSTDDEBUG -D_RWSTD_USE_CONFIG -I/build/sebor/dev/stdlib/include -I/build/sebor/gcc-4.1.0-11s/include -I/build/sebor/dev/stdlib/../rwtest -I/build/sebor/dev/stdlib/../rwtest/include -I/build/sebor/dev/stdlib/tests/include -pedantic -nostdinc++ -g -W -Wall -Wcast-qual -Winline -Wshadow -Wwrite-strings -Wno-long-long t.cpp
gcc t.o -o t -L/build/sebor/gcc-4.1.0-11s/rwtest -lrwtest11s -L/build/sebor/gcc-4.1.0-11s/lib -lstd11s -lsupc++ -lm
Assertion failed: 0 == pfb, file t.cpp, line 10
Abort (core dumped)



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Martin Sebor added a comment - 01/Jun/07 09:40 PM
This is actually by design and documented (for ifstream and ofstream) in the User's Guide. Classic Iostream behavior is the same as is C stdio. Quoting from http://incubator.apache.org/stdcxx/doc/stdlibug/index.html:

30.3.1.1 The in and out Open Modes

Input (and output) file streams always have the in (or out) open mode flag set implicitly. An output file stream, for instance, knows that it is in output mode and you need not set the output mode explicitly. Instead of writing:

std::ofstream Str("out.txt", std::ios_base::out | std::ios_base::app);

you can simply say:

std::ofstream Str("out.txt", std::ios_base::app);

Bidirectional file streams, on the other hand, do not have the flag set implicitly. This is because a bidirectional stream does not have to be in both input and output mode in all cases. You might want to open a bidirectional stream for reading only or writing only. Bidirectional file streams therefore have no implicit input or output mode. You must always set a bidirectional file stream's open mode explicitly.


Martin Sebor added a comment - 01/Jun/07 09:43 PM
So the issue should be addressed in the standard – see my post to the C++ reflector below:

-------- Original Message --------
Subject: another missing openmode (issue 596)
Date: Sun, 27 May 2007 17:06:54 -0600
From: Martin Sebor <sebor@roguewave.com>
Reply-To: c++std-lib@accu.org
Organization: Rogue Wave Software
To: undisclosed-recipients:;

To: C++ libraries mailing list
Message c++std-lib-18744

http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#596

...besides "a+" and "a+b" the C++ table is also missing a row
for a lone app bit which in at least two current implementation
as well as in Classic Iostreams corresponds to the C stdio "a"
mode and has been traditionally documented as implying ios::out.
Which means the table should also have a row for in|app meaning
the same thing as "a+" already proposed in the issue.

Howard, unless this is somehow implied somewhere else in the text
and I missed it, can you please add my comments to the issue?

Thanks
Martin


Martin Sebor added a comment - 23/Aug/07 10:20 PM
Added LWG #596 tag to the Summary to indicate a dependency on a Library Working Group issue, lowered Priority to Trivial (since it's by design), and deferred until after the C++ committee has had a chance to review the issue.

Martin Sebor made changes - 23/Aug/07 10:20 PM
Field Original Value New Value
Priority Major [ 3 ] Trivial [ 5 ]
Fix Version/s 4.2.1 [ 12312690 ]
Summary std::filebuf::open(..., ios::app) unexpectedly succeeds [LWG #596] std::filebuf::open(..., ios::app) unexpectedly succeeds
Martin Sebor made changes - 21/Jan/08 06:47 PM
Remaining Estimate 2h [ 7200 ]
Original Estimate 2h [ 7200 ]
Severity Incorrect Behavior
Martin Sebor added a comment - 18/Mar/08 04:23 PM
LWG issue 596 is still in Review status. Deferred until the issue has been voted into the Working Paper.

Martin Sebor made changes - 18/Mar/08 04:23 PM
Fix Version/s 4.2.1 [ 12312690 ]
Fix Version/s 4.3 [ 12312692 ]