Skip to content

Commit 9cdc728

Browse files
committed
[std] Rephrase notes giving advice to the programmer.
Partially addresses ISO/CS 017 (C++20 DIS)
1 parent e0c15e4 commit 9cdc728

File tree

11 files changed

+58
-71
lines changed

11 files changed

+58
-71
lines changed

source/algorithms.tex

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,11 @@
203203
\pnum
204204
\begin{note}
205205
Unless otherwise specified, algorithms that take function objects as arguments
206-
are permitted to copy those function objects freely.
207-
Programmers for whom object identity is important should consider
208-
using a wrapper class that points to a noncopied implementation object
209-
such as \tcode{reference_wrapper<T>}\iref{refwrap}, or some equivalent solution.
206+
can copy those function objects freely.
207+
If object identity is important,
208+
a wrapper class that points to a noncopied implementation object
209+
such as \tcode{reference_wrapper<T>}\iref{refwrap}, or some equivalent solution,
210+
can be used.
210211
\end{note}
211212

212213
\pnum
@@ -390,11 +391,11 @@
390391
\begin{note}
391392
This implies that user-supplied function objects cannot rely on
392393
object identity of arguments for such input sequences.
393-
Users for whom the object identity of the arguments to these function objects
394-
is important should consider using a wrapping iterator
394+
If object identity of the arguments to these function objects
395+
is important, a wrapping iterator
395396
that returns a non-copied implementation object
396-
such as \tcode{reference_wrapper<T>}\iref{refwrap}
397-
or some equivalent solution.
397+
such as \tcode{reference_wrapper<T>}\iref{refwrap},
398+
or some equivalent solution, can be used.
398399
\end{note}
399400

400401
\pnum

source/containers.tex

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -773,18 +773,16 @@
773773
\pnum
774774
\begin{note}
775775
The sequence containers
776-
offer the programmer different complexity trade-offs and should be used
777-
accordingly.
776+
offer the programmer different complexity trade-offs.
778777
\tcode{vector}
779-
is the type of sequence container that should be used by default.
778+
is the sequence container that can be used by default.
780779
\tcode{array}
781-
should be used when the container has a fixed size known during translation.
780+
has a fixed size known during translation.
782781
\tcode{list} or \tcode{forward_list}
783-
should be used when there are frequent insertions and deletions from the
782+
supports frequent insertions and deletions from the
784783
middle of the sequence.
785784
\tcode{deque}
786-
is the data structure of choice
787-
when most insertions and deletions take place at the beginning or at the
785+
supports efficient insertions and deletions taking place at the beginning or at the
788786
end of the sequence.
789787
When choosing a container, remember \tcode{vector} is best;
790788
leave a comment to explain if you choose from the rest!

source/diagnostics.tex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,9 @@
843843
\begin{note}
844844
\tcode{error_category} objects are
845845
passed by reference, and two such objects
846-
are equal if they have the same address. This means that applications using
847-
custom \tcode{error_category} types should create a single object of each
848-
such type.
846+
are equal if they have the same address.
847+
If there is more than a single object of a custom \tcode{error_category} type,
848+
such equality comparisons can spuriously fail.
849849
\end{note}
850850

851851
\indexlibraryglobal{error_category}%

source/exceptions.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@
355355
\end{codeblock}
356356
\end{example}
357357
\begin{note}
358-
\setlength{\emergencystretch}{1em}
359-
Consequently, destructors should generally catch exceptions and not let them propa\-gate.
358+
If a destructor directly invoked by stack unwinding exits via an exception,
359+
\tcode{std::terminate} is invoked.
360360
\end{note}
361361

362362

source/iostreams.tex

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11994,7 +11994,7 @@
1199411994
the ASCII control characters (0x00 -- 0x1F) in filenames.
1199511995
\end{example}
1199611996
\begin{note}
11997-
For wide portability, users may wish to limit \grammarterm{filename}
11997+
Wider portability can be achieved by limiting \grammarterm{filename}
1199811998
characters to the POSIX Portable Filename Character Set: \\
1199911999
\tcode{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z} \\
1200012000
\tcode{a b c d e f g h i j k l m n o p q r s t u v w x y z} \\
@@ -14622,11 +14622,11 @@
1462214622

1462314623
\pnum
1462414624
\begin{note}
14625-
Programs performing directory iteration may wish to test if the
14626-
path obtained by dereferencing a directory iterator actually exists. It could be
14627-
a symbolic link to a non-existent file. Programs recursively
14628-
walking directory trees for purposes of removing and renaming entries may wish
14629-
to avoid following symbolic links.
14625+
A path obtained by dereferencing a directory iterator might not actually exist;
14626+
it could be a symbolic link to a non-existent file.
14627+
Recursively walking directory trees
14628+
for purposes of removing and renaming entries
14629+
might invalidate symbolic links that are being followed.
1463014630
\end{note}
1463114631

1463214632
\pnum
@@ -15147,9 +15147,9 @@
1514715147
\pnum
1514815148
\begin{note}
1514915149
Because hardware failures, network failures, file system races\iref{fs.race.behavior},
15150-
and many other kinds of errors occur frequently in file system operations, users should be aware
15151-
that any filesystem operation function, no matter how apparently innocuous, may encounter
15152-
an error; see~\ref{fs.err.report}.
15150+
and many other kinds of errors occur frequently in file system operations,
15151+
any filesystem operation function, no matter how apparently innocuous,
15152+
can encounter an error; see~\ref{fs.err.report}.
1515315153
\end{note}
1515415154

1515515155
\rSec3[fs.op.absolute]{Absolute}
@@ -15640,7 +15640,9 @@
1564015640
\pnum
1564115641
\begin{note}
1564215642
Some operating systems require symlink creation to
15643-
identify that the link is to a directory. Portable code should use \tcode{create_directory_symlink()} to create directory symlinks rather than \tcode{create_symlink()}
15643+
identify that the link is to a directory.
15644+
Thus, \tcode{create_symlink()} (instead of \tcode{create_directory_symlink()})
15645+
cannot be used reliably to create directory symlinks.
1564415646
\end{note}
1564515647

1564615648
\pnum

source/lib-intro.tex

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,13 +3049,6 @@
30493049
Objects constructed by the standard library that may hold a user-supplied pointer value
30503050
or an integer of type \tcode{std::intptr_t} shall store such values in a traceable
30513051
pointer location\iref{basic.stc.dynamic.safety}.
3052-
\begin{note}
3053-
Other libraries are
3054-
strongly encouraged to do the same, since not doing so may result in accidental use of
3055-
pointers that are not safely derived. Libraries that store pointers outside the user's
3056-
address space should make it appear that they are stored and retrieved from a traceable
3057-
pointer location.
3058-
\end{note}
30593052

30603053
\rSec3[value.error.codes]{Value of error codes}
30613054

source/preprocessor.tex

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,12 @@
711711

712712
\pnum
713713
\begin{note}
714-
Although an implementation can provide a mechanism for making arbitrary
715-
source files available to the \tcode{< >} search, in general
716-
programmers should use the \tcode{< >} form for headers provided
717-
with the implementation, and the \tcode{" "} form for sources
718-
outside the control of the implementation. For instance:
714+
An implementation can provide a mechanism for making arbitrary
715+
source files available to the \tcode{< >} search.
716+
However, using the \tcode{< >} form for headers provided
717+
with the implementation and the \tcode{" "} form for sources
718+
outside the control of the implementation
719+
achieves wider portability. For instance:
719720

720721
\begin{codeblock}
721722
#include <stdio.h>

source/strings.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3947,7 +3947,7 @@
39473947
\pnum
39483948
\begin{note}
39493949
The library provides implicit conversions from \tcode{const charT*} and \tcode{std::basic_string<charT, ...>} to \tcode{std::basic_string_view<charT, ...>} so that user code can accept just \tcode{std::basic_string_view<charT>} as a non-templated parameter wherever a sequence of characters is expected.
3950-
User-defined types should define their own implicit conversions to \tcode{std::basic_string_view} in order to interoperate with these functions.
3950+
User-defined types can define their own implicit conversions to \tcode{std::basic_string_view} in order to interoperate with these functions.
39513951
\end{note}
39523952

39533953
\rSec2[string.view.synop]{Header \tcode{<string_view>} synopsis}

source/support.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,7 @@
19851985
A function registered via \tcode{at_quick_exit}
19861986
is invoked by the thread that calls \tcode{quick_exit},
19871987
which can be a different thread
1988-
than the one that registered it, so registered functions should not rely on the identity
1988+
than the one that registered it, so registered functions cannot rely on the identity
19891989
of objects with thread storage duration.
19901990
\end{note}
19911991
After calling registered functions, \tcode{quick_exit} shall call \tcode{_Exit(status)}.

source/threads.tex

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,7 +2024,7 @@
20242024
\begin{note}
20252025
Construction and
20262026
destruction of an object of a mutex type need not be thread-safe; other
2027-
synchronization should be used to ensure that mutex objects are initialized
2027+
synchronization can be used to ensure that mutex objects are initialized
20282028
and visible to other threads.
20292029
\end{note}
20302030

@@ -4240,11 +4240,8 @@
42404240

42414241
\pnum
42424242
\begin{note}
4243-
The supplied lock will be held until the thread exits, and care
4244-
should be taken to ensure that this does not cause deadlock due to lock
4245-
ordering issues. After calling \tcode{notify_all_at_thread_exit} it is
4246-
recommended that the thread should be exited as soon as possible, and
4247-
that no blocking or time-consuming tasks are run on that thread.
4243+
The supplied lock is held until the thread exits,
4244+
which might cause deadlock due to lock ordering issues.
42484245
\end{note}
42494246

42504247
\pnum
@@ -4332,7 +4329,7 @@
43324329
wait.
43334330
This relaxes the usual rules, which would have required all wait calls to happen before
43344331
destruction. Only the notification to unblock the wait needs to happen before destruction.
4335-
The user should take care to ensure that no threads wait on \tcode{*this} once the destructor has
4332+
Undefined behavior ensues if a thread waits on \tcode{*this} once the destructor has
43364333
been started, especially when the waiting threads are calling the wait functions in a loop or
43374334
using the overloads of \tcode{wait}, \tcode{wait_for}, or \tcode{wait_until} that take a predicate.
43384335
\end{note}
@@ -4689,8 +4686,8 @@
46894686
All of the standard
46904687
mutex types meet this requirement. If a \tcode{Lock} type other than one of the
46914688
standard mutex types or a \tcode{unique_lock} wrapper for a standard mutex type
4692-
is used with \tcode{condition_variable_any}, the user should ensure that any
4693-
necessary synchronization is in place with respect to the predicate associated
4689+
is used with \tcode{condition_variable_any}, any
4690+
necessary synchronization is assumed to be in place with respect to the predicate associated
46944691
with the \tcode{condition_variable_any} instance.
46954692
\end{note}
46964693

@@ -4774,7 +4771,7 @@
47744771
wait.
47754772
This relaxes the usual rules, which would have required all wait calls to happen before
47764773
destruction. Only the notification to unblock the wait needs to happen before destruction.
4777-
The user should take care to ensure that no threads wait on \tcode{*this} once the destructor has
4774+
Undefined behavior ensues if a thread waits on \tcode{*this} once the destructor has
47784775
been started, especially when the waiting threads are calling the wait functions in a loop or
47794776
using the overloads of \tcode{wait}, \tcode{wait_for}, or \tcode{wait_until} that take a predicate.
47804777
\end{note}
@@ -6924,7 +6921,7 @@
69246921
\pnum
69256922
\begin{note}
69266923
Access to a value object stored in the shared state is
6927-
unsynchronized, so programmers should apply only those operations on \tcode{R} that do not
6924+
unsynchronized, so operations on \tcode{R} might
69286925
introduce a data race\iref{intro.multithread}.
69296926
\end{note}
69306927

@@ -7161,8 +7158,7 @@
71617158
to the shared state created by this call to \tcode{async}.
71627159
\begin{note}
71637160
If a future obtained from \tcode{async} is moved outside the local scope,
7164-
other code that uses the future should be aware that the future's destructor can
7165-
block for the shared state to become ready.
7161+
the future's destructor can block for the shared state to become ready.
71667162
\end{note}
71677163

71687164
\pnum

source/utilities.tex

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7352,7 +7352,7 @@
73527352

73537353
\pnum
73547354
\begin{note}
7355-
This function should be the inverse of \tcode{pointer_to}.
7355+
This function is intended to be the inverse of \tcode{pointer_to}.
73567356
If defined, it customizes the behavior of
73577357
the non-member function
73587358
\tcode{to_address}\iref{pointer.conversion}.
@@ -7442,10 +7442,10 @@
74427442

74437443
\pnum
74447444
\begin{note}
7445-
It is expected that calls to \tcode{declare_reachable(p)} will consume
7445+
It is expected that calls to \tcode{declare_reachable(p)} consume
74467446
a small amount of memory in addition to that occupied by the referenced object until the
7447-
matching call to \tcode{undeclare_reachable(p)} is encountered. Long running programs
7448-
should arrange that calls are matched.
7447+
matching call to \tcode{undeclare_reachable(p)} is encountered.
7448+
Thus, long-running programs where calls are not matched can exhibit a memory leak.
74497449
\end{note}
74507450
\end{itemdescr}
74517451

@@ -8371,11 +8371,7 @@
83718371
derived, at the expense of providing far fewer garbage collection and leak
83728372
detection options for \tcode{malloc()}-allocated objects. It also allows
83738373
\tcode{malloc()} to be implemented with a separate allocation arena, bypassing
8374-
the normal \tcode{declare_reachable()} implementation. The above functions
8375-
should never intentionally be used as a replacement for
8376-
\tcode{declare_reachable()}, and newly written code is strongly encouraged to
8377-
treat memory allocated with these functions as though it were allocated with
8378-
\tcode{operator new}.
8374+
the normal \tcode{declare_reachable()} implementation.
83798375
\end{note}
83808376

83818377
\pnum
@@ -9949,9 +9945,9 @@
99499945

99509946
\pnum
99519947
\begin{note}
9952-
To avoid the possibility of a dangling pointer, the
9953-
user of this constructor should ensure that \tcode{p} remains valid at
9954-
least until the ownership group of \tcode{r} is destroyed.
9948+
Use of this constructor leads to a dangling pointer
9949+
unless \tcode{p} remains valid
9950+
at least until the ownership group of \tcode{r} is destroyed.
99559951
\end{note}
99569952

99579953
\pnum
@@ -10325,8 +10321,8 @@
1032510321
\pnum
1032610322
\begin{note}
1032710323
When multiple threads
10328-
can affect the return value of \tcode{use_count()},
10329-
the result should be treated as approximate.
10324+
might affect the return value of \tcode{use_count()},
10325+
the result is approximate.
1033010326
In particular, \tcode{use_count() == 1} does not imply that accesses through
1033110327
a previously destroyed \tcode{shared_ptr} have in any sense completed.
1033210328
\end{note}

0 commit comments

Comments
 (0)