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

365. Lack of const-qualification in clause 27

Section: 99 [input.output] Status: CD1 Submitter: Walter Brown, Marc Paterno Opened: 2002-05-10 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [input.output].

View all issues with CD1 status.

Discussion:

Some stream and streambuf member functions are declared non-const, even thought they appear only to report information rather than to change an object's logical state. They should be declared const. See document N1360 for details and rationale.

The list of member functions under discussion: in_avail, showmanyc, tellg, tellp, is_open.

Related issue: 73

Proposed resolution:

In 27.8.1.5, 27.8.1.7, 27.8.1.8, 27.8.1.10, 27.8.1.11, and 27.8.1.13

Replace

  bool is_open();

with

  bool is_open() const;

Rationale:

Of the changes proposed in N1360, the only one that is safe is changing the filestreams' is_open to const. The LWG believed that this was NAD the first time it considered this issue (issue 73), but now thinks otherwise. The corresponding streambuf member function, after all,is already const.

The other proposed changes are less safe, because some streambuf functions that appear merely to report a value do actually perform mutating operations. It's not even clear that they should be considered "logically const", because streambuf has two interfaces, a public one and a protected one. These functions may, and often do, change the state as exposed by the protected interface, even if the state exposed by the public interface is unchanged.

Note that implementers can make this change in a binary compatible way by providing both overloads; this would be a conforming extension.