Title
conflicting ios_base fmtflags
Status
nad
Section
[fmtflags.state]
Submitter
Judy Ward

Created on 2000-12-30.00:00:00 last changed 163 months ago

Messages

Date: 2010-10-21.18:28:33

Rationale:

adjustfield, basefield, and floatfield are each multi-bit fields. It is possible to set multiple bits within each of those fields. (For example, dec and oct). These fields are used by locale facets. The LWG reviewed the way in which each of those three fields is used, and believes that in each case the behavior is well defined for any possible combination of bits. See for example Table 58, in [facet.num.put.virtuals], noting the requirement in paragraph 6 of that section.

Users are advised to use manipulators, or else use the two-argument version of setf, to avoid unexpected behavior.

Date: 2000-12-30.00:00:00

The Effects clause for ios_base::setf(fmtflags fmtfl) says "Sets fmtfl in flags()". What happens if the user first calls ios_base::scientific and then calls ios_base::fixed or vice-versa? This is an issue for all of the conflicting flags, i.e. ios_base::left and ios_base::right or ios_base::dec, ios_base::hex and ios_base::oct.

I see three possible solutions:

  1. Set ios_base::failbit whenever the user specifies a conflicting flag with one previously explicitly set. If the constructor is supposed to set ios_base::dec (see discussion below), then the user setting hex or oct format after construction will not set failbit.
  2. The last call to setf "wins", i.e. it clears any conflicting previous setting.
  3. All the flags that the user specifies are set, but when actually interpreting them, fixed always override scientific, right always overrides left, dec overrides hex which overrides oct.

Most existing implementations that I tried seem to conform to resolution #3, except that when using the iomanip manipulator hex or oct then that always overrides dec, but calling setf(ios_base::hex) doesn't.

There is a sort of related issue, which is that although the ios_base constructor says that each ios_base member has an indeterminate value after construction, all the existing implementations I tried explicitly set ios_base::dec.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg2119
2000-12-30 00:00:00admincreate