diff --git a/source/compatibility.tex b/source/compatibility.tex index 9d2ea7073f..7c79e812a6 100644 --- a/source/compatibility.tex +++ b/source/compatibility.tex @@ -2079,6 +2079,19 @@ \rSec2[diff.cpp17.input.output]{\ref{input.output}: input/output library} +\diffref{istream.extractors} +\change +Character array extraction only takes array types. +\rationale Increase safety via preventing buffer overflow at compile time. +\effect +Valid \CppXVII{} code may fail to compile in this International Standard: +\begin{codeblock} +auto p = new char[100]; +char q[100]; +std::cin >> std::setw(20) >> p; // ill-formed; previously well-formed +std::cin >> std::setw(20) >> q; // OK +\end{codeblock} + \diffref{ostream.inserters.character} \change Overload resolution for ostream inserters used with UTF-8 literals. diff --git a/source/iostreams.tex b/source/iostreams.tex index 15366cb798..9c81dcc835 100644 --- a/source/iostreams.tex +++ b/source/iostreams.tex @@ -4270,12 +4270,12 @@ template basic_istream& operator>>(basic_istream&, signed char&); - template - basic_istream& operator>>(basic_istream&, charT*); - template - basic_istream& operator>>(basic_istream&, unsigned char*); - template - basic_istream& operator>>(basic_istream&, signed char*); + template + basic_istream& operator>>(basic_istream&, charT(&)[N]); + template + basic_istream& operator>>(basic_istream&, unsigned char(&)[N]); + template + basic_istream& operator>>(basic_istream&, signed char(&)[N]); } \end{codeblock} @@ -4756,12 +4756,12 @@ \indexlibrarymember{operator>>}{basic_istream}% \begin{itemdecl} -template - basic_istream& operator>>(basic_istream& in, charT* s); -template - basic_istream& operator>>(basic_istream& in, unsigned char* s); -template - basic_istream& operator>>(basic_istream& in, signed char* s); +template + basic_istream& operator>>(basic_istream& in, charT (&s)[N]); +template + basic_istream& operator>>(basic_istream& in, unsigned char (&s)[N]); +template + basic_istream& operator>>(basic_istream& in, signed char (&s)[N]); \end{itemdecl} \begin{itemdescr} @@ -4774,17 +4774,12 @@ object is constructed, \tcode{operator>>} extracts characters and stores them into -successive locations of an array whose first element is designated by \tcode{s}. If \tcode{width()} is greater than zero, \tcode{n} is -\tcode{width()}. -Otherwise \tcode{n} is the number of elements -of the largest array of -\tcode{char_type} -that can store a terminating -\tcode{charT()}. +\tcode{min(size_t(width()), N)}. +Otherwise \tcode{n} is \tcode{N}. \tcode{n} is the maximum number of characters stored. \pnum