Skip to content

Commit 866c95d

Browse files
jensmaurerzygoloid
authored andcommitted
[std] Rephrase notes giving advice to the programmer.
Partially addresses ISO/CS 017 (C++20 DIS)
1 parent 75bea3c commit 866c95d

12 files changed

+62
-74
lines changed

source/algorithms.tex

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

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

401402
\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 appropriate in most circumstances.
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+
support 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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,10 @@
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 evaluate to \tcode{false}
849+
even for objects holding the same value.
849850
\end{note}
850851

851852
\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: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11153,8 +11153,8 @@
1115311153
\pnum
1115411154
\begin{note}
1115511155
The member functions of the provided stream buffer
11156-
might be called from \tcode{emit()} while a lock is held.
11157-
Care should be taken to ensure that this does not result in deadlock.
11156+
can be called from \tcode{emit()} while a lock is held,
11157+
which might result in a deadlock if used incautiously.
1115811158
\end{note}
1115911159

1116011160
\pnum
@@ -11988,7 +11988,7 @@
1198811988
the ASCII control characters (0x00 -- 0x1F) in filenames.
1198911989
\end{example}
1199011990
\begin{note}
11991-
For wide portability, users may wish to limit \grammarterm{filename}
11991+
Wider portability can be achieved by limiting \grammarterm{filename}
1199211992
characters to the POSIX Portable Filename Character Set: \\
1199311993
\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} \\
1199411994
\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} \\
@@ -14616,11 +14616,11 @@
1461614616

1461714617
\pnum
1461814618
\begin{note}
14619-
Programs performing directory iteration may wish to test if the
14620-
path obtained by dereferencing a directory iterator actually exists. It could be
14621-
a symbolic link to a non-existent file. Programs recursively
14622-
walking directory trees for purposes of removing and renaming entries may wish
14623-
to avoid following symbolic links.
14619+
A path obtained by dereferencing a directory iterator might not actually exist;
14620+
it could be a symbolic link to a non-existent file.
14621+
Recursively walking directory trees
14622+
for purposes of removing and renaming entries
14623+
might invalidate symbolic links that are being followed.
1462414624
\end{note}
1462514625

1462614626
\pnum
@@ -15141,9 +15141,9 @@
1514115141
\pnum
1514215142
\begin{note}
1514315143
Because hardware failures, network failures, file system races\iref{fs.race.behavior},
15144-
and many other kinds of errors occur frequently in file system operations, users should be aware
15145-
that any filesystem operation function, no matter how apparently innocuous, may encounter
15146-
an error; see~\ref{fs.err.report}.
15144+
and many other kinds of errors occur frequently in file system operations,
15145+
any filesystem operation function, no matter how apparently innocuous,
15146+
can encounter an error; see~\ref{fs.err.report}.
1514715147
\end{note}
1514815148

1514915149
\rSec3[fs.op.absolute]{Absolute}
@@ -15634,7 +15634,9 @@
1563415634
\pnum
1563515635
\begin{note}
1563615636
Some operating systems require symlink creation to
15637-
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()}
15637+
identify that the link is to a directory.
15638+
Thus, \tcode{create_symlink()} (instead of \tcode{create_directory_symlink()})
15639+
cannot be used reliably to create directory symlinks.
1563815640
\end{note}
1563915641

1564015642
\pnum

source/lex.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
source of the translation units containing these definitions is required
185185
to be available.
186186
\begin{note}
187-
An implementation could encode sufficient
187+
An implementation can choose to encode sufficient
188188
information into the translated translation unit so as to ensure the
189189
source is not required here.
190190
\end{note}

source/lib-intro.tex

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

30623055
\rSec3[value.error.codes]{Value of error codes}
30633056

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

@@ -4238,11 +4238,8 @@
42384238

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

42484245
\pnum
@@ -4330,7 +4327,7 @@
43304327
wait.
43314328
This relaxes the usual rules, which would have required all wait calls to happen before
43324329
destruction. Only the notification to unblock the wait needs to happen before destruction.
4333-
The user should take care to ensure that no threads wait on \tcode{*this} once the destructor has
4330+
Undefined behavior ensues if a thread waits on \tcode{*this} once the destructor has
43344331
been started, especially when the waiting threads are calling the wait functions in a loop or
43354332
using the overloads of \tcode{wait}, \tcode{wait_for}, or \tcode{wait_until} that take a predicate.
43364333
\end{note}
@@ -4687,8 +4684,8 @@
46874684
All of the standard
46884685
mutex types meet this requirement. If a \tcode{Lock} type other than one of the
46894686
standard mutex types or a \tcode{unique_lock} wrapper for a standard mutex type
4690-
is used with \tcode{condition_variable_any}, the user should ensure that any
4691-
necessary synchronization is in place with respect to the predicate associated
4687+
is used with \tcode{condition_variable_any}, any
4688+
necessary synchronization is assumed to be in place with respect to the predicate associated
46924689
with the \tcode{condition_variable_any} instance.
46934690
\end{note}
46944691

@@ -4772,7 +4769,7 @@
47724769
wait.
47734770
This relaxes the usual rules, which would have required all wait calls to happen before
47744771
destruction. Only the notification to unblock the wait needs to happen before destruction.
4775-
The user should take care to ensure that no threads wait on \tcode{*this} once the destructor has
4772+
Undefined behavior ensues if a thread waits on \tcode{*this} once the destructor has
47764773
been started, especially when the waiting threads are calling the wait functions in a loop or
47774774
using the overloads of \tcode{wait}, \tcode{wait_for}, or \tcode{wait_until} that take a predicate.
47784775
\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
@@ -7356,7 +7356,7 @@
73567356

73577357
\pnum
73587358
\begin{note}
7359-
This function should be the inverse of \tcode{pointer_to}.
7359+
This function is intended to be the inverse of \tcode{pointer_to}.
73607360
If defined, it customizes the behavior of
73617361
the non-member function
73627362
\tcode{to_address}\iref{pointer.conversion}.
@@ -7446,10 +7446,10 @@
74467446

74477447
\pnum
74487448
\begin{note}
7449-
It is expected that calls to \tcode{declare_reachable(p)} will consume
7449+
It is expected that calls to \tcode{declare_reachable(p)} consume
74507450
a small amount of memory in addition to that occupied by the referenced object until the
7451-
matching call to \tcode{undeclare_reachable(p)} is encountered. Long running programs
7452-
should arrange that calls are matched.
7451+
matching call to \tcode{undeclare_reachable(p)} is encountered.
7452+
Thus, long-running programs where calls are not matched can exhibit a memory leak.
74537453
\end{note}
74547454
\end{itemdescr}
74557455

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

83858381
\pnum
@@ -9954,9 +9950,9 @@
99549950

99559951
\pnum
99569952
\begin{note}
9957-
To avoid the possibility of a dangling pointer, the
9958-
user of this constructor should ensure that \tcode{p} remains valid at
9959-
least until the ownership group of \tcode{r} is destroyed.
9953+
Use of this constructor leads to a dangling pointer
9954+
unless \tcode{p} remains valid
9955+
at least until the ownership group of \tcode{r} is destroyed.
99609956
\end{note}
99619957

99629958
\pnum
@@ -10330,8 +10326,8 @@
1033010326
\pnum
1033110327
\begin{note}
1033210328
When multiple threads
10333-
can affect the return value of \tcode{use_count()},
10334-
the result should be treated as approximate.
10329+
might affect the return value of \tcode{use_count()},
10330+
the result is approximate.
1033510331
In particular, \tcode{use_count() == 1} does not imply that accesses through
1033610332
a previously destroyed \tcode{shared_ptr} have in any sense completed.
1033710333
\end{note}

0 commit comments

Comments
 (0)