444. Bad use of casts in fstream

Section: 30.9 [file.streams] Status: CD1 Submitter: Vincent Leloup Opened: 2003-11-20 Last modified: 2017-06-16

Priority: Not Prioritized

View all other issues in [file.streams].

View all issues with CD1 status.

Discussion:

30.9.3.3 [ifstream.members] p1, 30.9.4.3 [ofstream.members] p1, 30.9.5.3 [fstream.members] p1 seems have same problem as exposed in LWG issue 252.

Proposed resolution:

[Sydney: Genuine defect. 27.8.1.13 needs a cast to cast away constness. The other two places are stylistic: we could change the C-style casts to const_cast. Post-Sydney: Howard provided wording. ]

Change 27.8.1.7/1 from:

Returns: (basic_filebuf<charT,traits>*)&sb.

to:

Returns: const_cast<basic_filebuf<charT,traits>*>(&sb).

Change 27.8.1.10/1 from:

Returns: (basic_filebuf<charT,traits>*)&sb.

to:

Returns: const_cast<basic_filebuf<charT,traits>*>(&sb).

Change 27.8.1.13/1 from:

Returns: &sb.

to:

Returns: const_cast<basic_filebuf<charT,traits>*>(&sb).