It seems to me, that there is an inconsistency in the C++ standard, specifically in §30.7.5.2.4 of the C++17 draft (N4659), about when characters are widened in formatted output operations on output streams (operator<<()
). Exactly the same inconsistency seems to be reflected in en.cppreference.com.
First, assume the following declarations:
std::ostream out;
std::wostream wout;
char ch;
wchar_t wch;
const char* str;
const wchar_t* wstr;
It is then stated that
out << ch
does not perform character widening,out << str
performs character widening,wout << ch
performs character widening,wout << str
performs character widening,wout << wch
does not perform character widening,wout << wstr
performs character widening.
The first and most obvious inconsistency is that (6) cannot be true, as there is no widen()
function taking a wchar_t
argument, only one that takes a char
argument.
The second (seeming) inconsistency is between (1) and (2). It seems strange to me that out << "x"
should widen 'x'
, while out << 'x'
should not.
Am I misinterpreting the standard text, or is there something wrong there? If the latter is true, do you know what the intended behavior is?
EDIT: Apparently, this inconsistency (if I am right), has been present in the standard since at least C++03 (§27.6.2.5.4). The text changes a bit through the intermediate standards, but the inconsistency, as I explain it above, remains.