Skip to content

Commit e1fc427

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

12 files changed

+62
-74
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 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

@@ -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}
@@ -6926,7 +6923,7 @@
69266923
\pnum
69276924
\begin{note}
69286925
Access to a value object stored in the shared state is
6929-
unsynchronized, so programmers should apply only those operations on \tcode{R} that do not
6926+
unsynchronized, so operations on \tcode{R} might
69306927
introduce a data race\iref{intro.multithread}.
69316928
\end{note}
69326929

@@ -7163,8 +7160,7 @@
71637160
to the shared state created by this call to \tcode{async}.
71647161
\begin{note}
71657162
If a future obtained from \tcode{async} is moved outside the local scope,
7166-
other code that uses the future should be aware that the future's destructor can
7167-
block for the shared state to become ready.
7163+
the future's destructor can block for the shared state to become ready.
71687164
\end{note}
71697165

71707166
\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)