Working Draft, Standard for Programming Language C++ (N4713, 2017 year) - page 43

 

  Главная      Manuals     Working Draft, Standard for Programming Language C++ (N4713, 2017 year)

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     41      42      43      44     ..

 

 

 

Working Draft, Standard for Programming Language C++ (N4713, 2017 year) - page 43

 

 

(15.1)
wait()s until the shared state is ready, then retrieves the value stored in the shared state;
(15.2)
releases any shared state (33.6.5).
16
Returns:
(16.1)
future::get() returns the value v stored in the object’s shared state as std::move(v).
(16.2)
future<R&>::get() returns the reference stored as value in the object’s shared state.
(16.3)
future<void>::get() returns nothing.
17
Throws: The stored exception, if an exception was stored in the shared state.
18
Postconditions: valid() == false.
bool valid() const noexcept;
19
Returns: true only if *this refers to a shared state.
void wait() const;
20
Effects: Blocks until the shared state is ready.
template<class Rep, class Period>
future_status wait_for(const chrono::duration<Rep, Period>& rel_time) const;
21
Effects: None if the shared state contains a deferred function (33.6.9), otherwise blocks until the shared
state is ready or until the relative timeout (33.2.4) specified by rel_time has expired.
22
Returns:
(22.1)
future_status::deferred if the shared state contains a deferred function.
(22.2)
future_status::ready if the shared state is ready.
(22.3)
future_status::timeout if the function is returning because the relative timeout (33.2.4) specified
by rel_time has expired.
23
Throws: timeout-related exceptions (33.2.4).
template<class Clock, class Duration>
future_status wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
24
Effects: None if the shared state contains a deferred function (33.6.9), otherwise blocks until the shared
state is ready or until the absolute timeout (33.2.4) specified by abs_time has expired.
25
Returns:
(25.1)
future_status::deferred if the shared state contains a deferred function.
(25.2)
future_status::ready if the shared state is ready.
(25.3)
future_status::timeout if the function is returning because the absolute timeout (33.2.4)
specified by abs_time has expired.
26
Throws: timeout-related exceptions (33.2.4).
33.6.8
Class template shared_future
[futures.shared_future]
1
The class template shared_future defines a type for asynchronous return objects which may share their
shared state with other asynchronous return objects. A default-constructed shared_future object has no
shared state. A shared_future object with shared state can be created by conversion from a future object
and shares its shared state with the original asynchronous provider (33.6.5) of the shared state. The result
(value or exception) of a shared_future object can be set by calling a respective function on an object that
shares the same shared state.
2
[ Note: Member functions of shared_future do not synchronize with themselves, but they synchronize with
the shared state.
— end note ]
3
The effect of calling any member function other than the destructor, the move-assignment operator, the
copy-assignment operator, or valid() on a shared_future object for which valid() == false is undefined.
[ Note: It is valid to copy or move from a shared_future object for which valid() is false.
— end note ]
[Note: Implementations should detect this case and throw an object of type future_error with an error
condition of future_errc::no_state.
— end note ]
§ 33.6.8
1252
namespace std {
template<class R>
class shared_future {
public:
shared_future() noexcept;
shared_future(const shared_future& rhs) noexcept;
shared_future(future<R>&&) noexcept;
shared_future(shared_future&& rhs) noexcept;
~shared_future();
shared_future& operator=(const shared_future& rhs) noexcept;
shared_future& operator=(shared_future&& rhs) noexcept;
// retrieving the value
see below get() const;
// functions to check state
bool valid() const noexcept;
void wait() const;
template<class Rep, class Period>
future_status wait_for(const chrono::duration<Rep, Period>& rel_time) const;
template<class Clock, class Duration>
future_status wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
};
}
4
The implementation shall provide the template shared_future and two specializations, shared_future<R&>
and shared_future<void>. These differ only in the return type and return value of the member function
get, as set out in its description, below.
shared_future() noexcept;
5
Effects: Constructs an empty shared_future object that does not refer to a shared state.
6
Postconditions: valid() == false.
shared_future(const shared_future& rhs) noexcept;
7
Effects: Constructs a shared_future object that refers to the same shared state as rhs (if any).
8
Postconditions: valid() returns the same value as rhs.valid().
shared_future(future<R>&& rhs) noexcept;
shared_future(shared_future&& rhs) noexcept;
9
Effects: Move constructs a shared_future object that refers to the shared state that was originally
referred to by rhs (if any).
10
Postconditions:
(10.1)
valid() returns the same value as rhs.valid() returned prior to the constructor invocation.
(10.2)
rhs.valid() == false.
~shared_future();
11
Effects:
(11.1)
Releases any shared state (33.6.5);
(11.2)
destroys *this.
shared_future& operator=(shared_future&& rhs) noexcept;
12
Effects:
(12.1)
Releases any shared state (33.6.5);
(12.2)
move assigns the contents of rhs to *this.
13
Postconditions:
(13.1)
valid() returns the same value as rhs.valid() returned prior to the assignment.
§ 33.6.8
1253
(13.2)
rhs.valid() == false.
shared_future& operator=(const shared_future& rhs) noexcept;
14
Effects:
(14.1)
Releases any shared state (33.6.5);
(14.2)
assigns the contents of rhs to *this. [ Note: As a result, *this refers to the same shared state as
rhs (if any).
— end note ]
15
Postconditions: valid() == rhs.valid().
const R& shared_future::get() const;
R& shared_future<R&>::get() const;
void shared_future<void>::get() const;
16
[ Note: As described above, the template and its two required specializations differ only in the return
type and return value of the member function get.
— end note ]
17
[Note: Access to a value object stored in the shared state is unsynchronized, so programmers should
apply only those operations on R that do not introduce a data race (6.8.2).
— end note ]
18
Effects: wait()s until the shared state is ready, then retrieves the value stored in the shared state.
19
Returns:
(19.1)
shared_future::get() returns a const reference to the value stored in the object’s shared state.
[ Note: Access through that reference after the shared state has been destroyed produces undefined
behavior; this can be avoided by not storing the reference in any storage with a greater lifetime
than the shared_future object that returned the reference.
— end note ]
(19.2)
shared_future<R&>::get() returns the reference stored as value in the object’s shared state.
(19.3)
shared_future<void>::get() returns nothing.
20
Throws: The stored exception, if an exception was stored in the shared state.
bool valid() const noexcept;
21
Returns: true only if *this refers to a shared state.
void wait() const;
22
Effects: Blocks until the shared state is ready.
template<class Rep, class Period>
future_status wait_for(const chrono::duration<Rep, Period>& rel_time) const;
23
Effects: None if the shared state contains a deferred function (33.6.9), otherwise blocks until the shared
state is ready or until the relative timeout (33.2.4) specified by rel_time has expired.
24
Returns:
(24.1)
future_status::deferred if the shared state contains a deferred function.
(24.2)
future_status::ready if the shared state is ready.
(24.3)
future_status::timeout if the function is returning because the relative timeout (33.2.4) specified
by rel_time has expired.
25
Throws: timeout-related exceptions (33.2.4).
template<class Clock, class Duration>
future_status wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
26
Effects: None if the shared state contains a deferred function (33.6.9), otherwise blocks until the shared
state is ready or until the absolute timeout (33.2.4) specified by abs_time has expired.
27
Returns:
(27.1)
future_status::deferred if the shared state contains a deferred function.
(27.2)
future_status::ready if the shared state is ready.
(27.3)
future_status::timeout if the function is returning because the absolute timeout (33.2.4)
specified by abs_time has expired.
§ 33.6.8
1254
28
Throws: timeout-related exceptions (33.2.4).
33.6.9
Function template async
[futures.async]
1
The function template async provides a mechanism to launch a function potentially in a new thread and
provides the result of the function in a future object with which it shares a shared state.
template<class F, class... Args>
[[nodiscard]] future<invoke_result_t<decay_t<F>, decay_t<Args>...>>
async(F&& f, Args&&... args);
template<class F, class... Args>
[[nodiscard]] future<invoke_result_t<decay_t<F>, decay_t<Args>...>>
async(launch policy, F&& f, Args&&... args);
2
Requires: F and each Ti in Args shall satisfy the MoveConstructible requirements, and
INVOKE(DECAY_COPY(std::forward<F>(f)),
DECAY_COPY(std::forward<Args>(args))...)
// see 23.14.3, 33.3.2.2
shall be a valid expression.
3
Effects: The first function behaves the same as a call to the second function with a policy argument of
launch::async | launch::deferred and the same arguments for F and Args. The second function
creates a shared state that is associated with the returned future object. The further behavior of
the second function depends on the policy argument as follows (if more than one of these conditions
applies, the implementation may choose any of the corresponding policies):
(3.1)
If launch::async is set in policy, calls INVOKE(DECAY_COPY(std::forward<F>(f)), DECAY_-
COPY(std::forward<Args>(args))...) (23.14.3, 33.3.2.2) as if in a new thread of execution
represented by a thread object with the calls to DECAY_COPY being evaluated in the thread
that called async. Any return value is stored as the result in the shared state. Any excep-
tion propagated from the execution of INVOKE(DECAY_COPY(std::forward<F>(f)), DECAY_-
COPY(std::forward<Args>(args))...) is stored as the exceptional result in the shared state.
The thread object is stored in the shared state and affects the behavior of any asynchronous
return objects that reference that state.
(3.2)
If launch::deferred is set in policy, stores DECAY_COPY(std::forward<F>(f)) and DECAY_-
COPY(std::forward<Args>(args))... in the shared state. These copies of f and args consti-
tute a deferred function. Invocation of the deferred function evaluates INVOKE(std::move(g),
std::move(xyz)) where g is the stored value of DECAY_COPY(std::forward<F>(f)) and xyz is
the stored copy of DECAY_COPY(std::forward<Args>(args))
Any return value is stored as
the result in the shared state. Any exception propagated from the execution of the deferred
function is stored as the exceptional result in the shared state. The shared state is not made
ready until the function has completed. The first call to a non-timed waiting function (33.6.5)
on an asynchronous return object referring to this shared state shall invoke the deferred func-
tion in the thread that called the waiting function. Once evaluation of INVOKE(std::move(g),
std::move(xyz)) begins, the function is no longer considered deferred. [ Note: If this policy is
specified together with other policies, such as when using a policy value of launch::async |
launch::deferred, implementations should defer invocation or the selection of the policy when
no more concurrency can be effectively exploited.
— end note ]
(3.3)
If no value is set in the launch policy, or a value is set that is neither specified in this document
nor by the implementation, the behavior is undefined.
4
Returns: An object of type future<invoke_result_t<decay_t<F>, decay_t<Args>...>> that refers
to the shared state created by this call to async. [Note: If a future obtained from async is moved
outside the local scope, other code that uses the future should be aware that the future’s destructor
may block for the shared state to become ready.
— end note ]
5
Synchronization: Regardless of the provided policy argument,
(5.1)
the invocation of async synchronizes with (6.8.2) the invocation of f.
[Note: This statement
applies even when the corresponding future object is moved to another thread.
— end note ] ;
and
(5.2)
the completion of the function f is sequenced before (6.8.2) the shared state is made ready. [ Note:
f might not be called at all, so its completion might never happen.
— end note ]
§
33.6.9
1255
If the implementation chooses the launch::async policy,
(5.3)
a call to a waiting function on an asynchronous return object that shares the shared state created
by this async call shall block until the associated thread has completed, as if joined, or else time
out (33.3.2.5);
(5.4)
the associated thread completion synchronizes with (6.8.2) the return from the first function that
successfully detects the ready status of the shared state or with the return from the last function
that releases the shared state, whichever happens first.
6
Throws: system_error if policy == launch::async and the implementation is unable to start a new
thread, or std::bad_alloc if memory for the internal data structures could not be allocated.
7
Error conditions:
(7.1)
resource_unavailable_try_again — if policy == launch::async and the system is unable
to start a new thread.
8
[ Example:
int work1(int value);
int work2(int value);
int work(int value) {
auto handle = std::async([=]{ return work2(value); });
int tmp = work1(value);
return tmp + handle.get();
// #1
}
[Note: Line #1 might not result in concurrency because the async call uses the default policy, which may
use launch::deferred, in which case the lambda might not be invoked until the get() call; in that case,
work1 and work2 are called on the same thread and there is no concurrency.
— end note ]
— end example ]
33.6.10
Class template packaged_task
[futures.task]
1
The class template packaged_task defines a type for wrapping a function or callable object so that the
return value of the function or callable object is stored in a future when it is invoked.
2
When the packaged_task object is invoked, its stored task is invoked and the result (whether normal or
exceptional) stored in the shared state. Any futures that share the shared state will then be able to access
the stored result.
namespace std {
template<class> class packaged_task; // not defined
template<class R, class... ArgTypes>
class packaged_task<R(ArgTypes...)> {
public:
// construction and destruction
packaged_task() noexcept;
template<class F>
explicit packaged_task(F&& f);
~packaged_task();
// no copy
packaged_task(const packaged_task&) = delete;
packaged_task& operator=(const packaged_task&) = delete;
// move support
packaged_task(packaged_task&& rhs) noexcept;
packaged_task& operator=(packaged_task&& rhs) noexcept;
void swap(packaged_task& other) noexcept;
bool valid() const noexcept;
// result retrieval
future<R> get_future();
// execution
void operator()(ArgTypes... );
§ 33.6.10
1256
void make_ready_at_thread_exit(ArgTypes...);
void reset();
};
template<class R, class... ArgTypes>
void swap(packaged_task<R(ArgTypes...)>& x, packaged_task<R(ArgTypes...)>& y) noexcept;
}
33.6.10.1
packaged_task member functions
[futures.task.members]
packaged_task() noexcept;
1
Effects: Constructs a packaged_task object with no shared state and no stored task.
template<class F>
packaged_task(F&& f);
2
Requires: INVOKE<R>(f, t1, t2, . . . , tN ) (23.14.3), where t1, t2, . . . , tN are values of the cor-
responding types in ArgTypes..., shall be a valid expression. Invoking a copy of f shall behave the
same as invoking f.
3
Remarks: This constructor shall not participate in overload resolution if decay_t<F> is the same type
as packaged_task<R(ArgTypes...)>.
4
Effects: Constructs a new packaged_task object with a shared state and initializes the object’s stored
task with std::forward<F>(f).
5
Throws: Any exceptions thrown by the copy or move constructor of f, or bad_alloc if memory for the
internal data structures could not be allocated.
packaged_task(packaged_task&& rhs) noexcept;
6
Effects: Constructs a new packaged_task object and transfers ownership of rhs’s shared state to
*this, leaving rhs with no shared state. Moves the stored task from rhs to *this.
7
Postconditions: rhs has no shared state.
packaged_task& operator=(packaged_task&& rhs) noexcept;
8
Effects:
(8.1)
Releases any shared state (33.6.5);
(8.2)
calls packaged_task(std::move(rhs)).swap(*this).
~packaged_task();
9
Effects: Abandons any shared state (33.6.5).
void swap(packaged_task& other) noexcept;
10
Effects: Exchanges the shared states and stored tasks of *this and other.
11
Postconditions: *this has the same shared state and stored task (if any) as other prior to the call to
swap. other has the same shared state and stored task (if any) as *this prior to the call to swap.
bool valid() const noexcept;
12
Returns: true only if *this has a shared state.
future<R> get_future();
13
Returns: A future object that shares the same shared state as *this.
14
Throws: A future_error object if an error occurs.
15
Error conditions:
(15.1)
future_already_retrieved if get_future has already been called on a packaged_task object
with the same shared state as *this.
(15.2)
no_state if *this has no shared state.
§ 33.6.10.1
1257
void
operator()(ArgTypes... args);
16
Effects: As if by INVOKE<R>(f, t1, t2, . . . , tN ) (23.14.3), where f is the stored task of *this and
t1, t2, ..., tN are the values in args
If the task returns normally, the return value is stored as
the asynchronous result in the shared state of *this, otherwise the exception thrown by the task is
stored. The shared state of *this is made ready, and any threads blocked in a function waiting for the
shared state of *this to become ready are unblocked.
17
Throws: A future_error exception object if there is no shared state or the stored task has already
been invoked.
18
Error conditions:
(18.1)
promise_already_satisfied if the stored task has already been invoked.
(18.2)
no_state if *this has no shared state.
void
make_ready_at_thread_exit(ArgTypes... args);
19
Effects: As if by INVOKE<R>(f, t1, t2, . . . , tN ) (23.14.3), where f is the stored task and t1, t2,
..., tN are the values in args
If the task returns normally, the return value is stored as the
asynchronous result in the shared state of *this, otherwise the exception thrown by the task is stored.
In either case, this shall be done without making that state ready (33.6.5) immediately. Schedules
the shared state to be made ready when the current thread exits, after all objects of thread storage
duration associated with the current thread have been destroyed.
20
Throws: future_error if an error condition occurs.
21
Error conditions:
(21.1)
promise_already_satisfied if the stored task has already been invoked.
(21.2)
no_state if *this has no shared state.
void
reset();
22
Effects: As if *this = packaged_task(std::move(f)), where f is the task stored in *this. [ Note:
This constructs a new shared state for *this. The old state is abandoned (33.6.5).
— end note ]
23
Throws:
(23.1)
bad_alloc if memory for the new shared state could not be allocated.
(23.2)
any exception thrown by the move constructor of the task stored in the shared state.
(23.3)
future_error with an error condition of no_state if *this has no shared state.
33.6.10.2
packaged_task globals
[futures.task.nonmembers]
template<class R, class... ArgTypes>
void swap(packaged_task<R(ArgTypes...)>& x, packaged_task<R(ArgTypes...)>& y) noexcept;
1
Effects: As if by x.swap(y).
§ 33.6.10.2
1258
Annex A
(informative)
Grammar summary
[gram]
1
This summary of C++ grammar is intended to be an aid to comprehension. It is not an exact statement
of the language. In particular, the grammar described here accepts a superset of valid C++ constructs.
Disambiguation rules (9.8, 10.1, 13.2) must be applied to distinguish expressions from declarations. Further,
access control, ambiguity, and type rules must be used to weed out syntactically valid but meaningless
constructs.
A.1
Keywords
[gram.key]
1
New context-dependent keywords are introduced into a program by typedef (10.1.3), namespace (10.3.1),
class (Clause 12), enumeration (10.2), and template (Clause 17) declarations.
typedef-name:
identifier
namespace-name:
identifier
namespace-alias
namespace-alias:
identifier
class-name:
identifier
simple-template-id
enum-name:
identifier
template-name:
identifier
Note that a typedef-name naming a class is also a class-name (12.1).
A.2
Lexical conventions
[gram.lex]
hex-quad:
hexadecimal-digit hexadecimal-digit hexadecimal-digit hexadecimal-digit
universal-character-name:
\u hex-quad
\U hex-quad hex-quad
preprocessing-token:
header-name
identifier
pp-number
character-literal
user-defined-character-literal
string-literal
user-defined-string-literal
preprocessing-op-or-punc
each non-white-space character that cannot be one of the above
token:
identifier
keyword
literal
operator
punctuator
header-name:
< h-char-sequence >
" q-char-sequence "
§ A.2
1259
h-char-sequence:
h-char
h-char-sequence h-char
h-char:
any member of the source character set except new-line and >
q-char-sequence:
q-char
q-char-sequence q-char
q-char:
any member of the source character set except new-line and "
pp-number:
digit
. digit
pp-number digit
pp-number identifier-nondigit
pp-number ’ digit
pp-number ’ nondigit
pp-number e sign
pp-number E sign
pp-number p sign
pp-number P sign
pp-number .
identifier:
identifier-nondigit
identifier identifier-nondigit
identifier digit
identifier-nondigit:
nondigit
universal-character-name
nondigit: one of
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
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
_
digit: one of
0 1 2 3 4 5 6 7 8 9
preprocessing-op-or-punc: one of
{
}
[
]
#
##
(
)
<:
:>
<%
%>
%:
%:%:
;
:
new
delete
?
::
.*
->
->*
~
!
+
-
/
%
^
&
|
=
+=
-=
*=
/=
%=
^=
&=
|=
==
!=
<
>
<=
>=
<=>
&&
||
<<
>>
<<=
>>=
++
--
,
and
or
xor
not
bitand
bitor
compl
and_eq
or_eq
xor_eq
not_eq
literal:
integer-literal
character-literal
floating-literal
string-literal
boolean-literal
pointer-literal
user-defined-literal
integer-literal:
binary-literal integer-suffixopt
octal-literal integer-suffixopt
decimal-literal integer-suffixopt
hexadecimal-literal integer-suffixopt
§ A.2
1260
binary-literal:
0b binary-digit
0B binary-digit
binary-literal ’opt binary-digit
octal-literal:
0
octal-literal ’opt octal-digit
decimal-literal:
nonzero-digit
decimal-literal ’opt digit
hexadecimal-literal:
hexadecimal-prefix hexadecimal-digit-sequence
binary-digit:
0
1
octal-digit: one of
0 1 2 3 4 5 6 7
nonzero-digit: one of
1 2 3 4 5 6 7 8 9
hexadecimal-prefix: one of
0x 0X
hexadecimal-digit-sequence:
hexadecimal-digit
hexadecimal-digit-sequence ’opt hexadecimal-digit
hexadecimal-digit: one of
0 1 2 3 4 5 6 7 8 9
a b c d e f
A B C D E F
integer-suffix:
unsigned-suffix long-suffixopt
unsigned-suffix long-long-suffixopt
long-suffix unsigned-suffixopt
long-long-suffix unsigned-suffixopt
unsigned-suffix: one of
u U
long-suffix: one of
l L
long-long-suffix: one of
ll LL
character-literal:
encoding-prefixopt ’ c-char-sequence ’
encoding-prefix: one of
u8
u U L
c-char-sequence:
c-char
c-char-sequence c-char
c-char:
any member of the source character set except
the single-quote ’, backslash \, or new-line character
escape-sequence
universal-character-name
escape-sequence:
simple-escape-sequence
octal-escape-sequence
hexadecimal-escape-sequence
§ A.2
1261
simple-escape-sequence: one of
\’
\"
\?
\\
\a
\b
\f
\n
\r
\t
\v
octal-escape-sequence:
\ octal-digit
\ octal-digit octal-digit
\ octal-digit octal-digit octal-digit
hexadecimal-escape-sequence:
\x hexadecimal-digit
hexadecimal-escape-sequence hexadecimal-digit
floating-literal:
decimal-floating-literal
hexadecimal-floating-literal
decimal-floating-literal:
fractional-constant exponent-partopt floating-suffixopt
digit-sequence exponent-part floating-suffixopt
hexadecimal-floating-literal:
hexadecimal-prefix hexadecimal-fractional-constant binary-exponent-part floating-suffixopt
hexadecimal-prefix hexadecimal-digit-sequence binary-exponent-part floating-suffixopt
fractional-constant:
digit-sequenceopt . digit-sequence
digit-sequence .
hexadecimal-fractional-constant:
hexadecimal-digit-sequenceopt . hexadecimal-digit-sequence
hexadecimal-digit-sequence .
exponent-part:
e signopt digit-sequence
E signopt digit-sequence
binary-exponent-part:
p signopt digit-sequence
P signopt digit-sequence
sign: one of
+ -
digit-sequence:
digit
digit-sequence ’opt digit
floating-suffix: one of
f l F L
string-literal:
encoding-prefixopt " s-char-sequenceopt "
encoding-prefixopt R raw-string
s-char-sequence:
s-char
s-char-sequence s-char
s-char:
any member of the source character set except
the double-quote ", backslash \, or new-line character
escape-sequence
universal-character-name
raw-string:
" d-char-sequenceopt ( r-char-sequenceopt ) d-char-sequenceopt "
r-char-sequence:
r-char
r-char-sequence r-char
§ A.2
1262
r-char:
any member of the source character set, except
a right parenthesis ) followed by the initial d-char-sequence
(which may be empty) followed by a double quote ".
d-char-sequence:
d-char
d-char-sequence d-char
d-char:
any member of the basic source character set except:
space, the left parenthesis (, the right parenthesis ), the backslash \,
and the control characters representing horizontal tab,
vertical tab, form feed, and newline.
boolean-literal:
false
true
pointer-literal:
nullptr
user-defined-literal:
user-defined-integer-literal
user-defined-floating-literal
user-defined-string-literal
user-defined-character-literal
user-defined-integer-literal:
decimal-literal ud-suffix
octal-literal ud-suffix
hexadecimal-literal ud-suffix
binary-literal ud-suffix
user-defined-floating-literal:
fractional-constant exponent-partopt ud-suffix
digit-sequence exponent-part ud-suffix
hexadecimal-prefix hexadecimal-fractional-constant binary-exponent-part ud-suffix
hexadecimal-prefix hexadecimal-digit-sequence binary-exponent-part ud-suffix
user-defined-string-literal:
string-literal ud-suffix
user-defined-character-literal:
character-literal ud-suffix
ud-suffix:
identifier
A.3
Basic concepts
[gram.basic]
translation-unit:
declaration-seqopt
A.4
Expressions
[gram.expr]
primary-expression:
literal
this
( expression )
id-expression
lambda-expression
fold-expression
requires-expression
id-expression:
unqualified-id
qualified-id
§ A.4
1263
unqualified-id:
identifier
operator-function-id
conversion-function-id
literal-operator-id
~ class-name
~ decltype-specifier
template-id
qualified-id:
nested-name-specifier templateopt unqualified-id
nested-name-specifier:
::
type-name ::
namespace-name ::
decltype-specifier ::
nested-name-specifier identifier ::
nested-name-specifier templateopt simple-template-id ::
lambda-expression:
lambda-introducer compound-statement
lambda-introducer lambda-declarator requires-clauseopt compound-statement
lambda-introducer < template-parameter-list > requires-clauseopt compound-statement
lambda-introducer < template-parameter-list > requires-clauseopt
lambda-declarator requires-clauseopt compound-statement
lambda-introducer:
[ lambda-captureopt ]
lambda-declarator:
( parameter-declaration-clause ) decl-specifier-seqopt
noexcept-specifieropt attribute-specifier-seqopt trailing-return-typeopt
lambda-capture:
capture-default
capture-list
capture-default , capture-list
capture-default:
&
=
capture-list:
capture ...opt
capture-list , capture ...opt
capture:
simple-capture
init-capture
simple-capture:
identifier
& identifier
this
* this
init-capture:
identifier initializer
& identifier initializer
fold-expression:
( cast-expression fold-operator ... )
( ... fold-operator cast-expression )
( cast-expression fold-operator ... fold-operator cast-expression )
fold-operator: one of
+
-
/
%
^ &
|
<<
>>
+=
-=
*=
/=
%=
^= &=
|=
<<=
>>=
=
==
!=
<
>
<=
>= &&
||
,
.*
->*
§ A.4
1264
requires-expression:
requires requirement-parameter-listopt requirement-body
requirement-parameter-list:
( parameter-declaration-clauseopt )
requirement-body:
{ requirement-seq }
requirement-seq:
requirement
requirement-seq requirement
requirement:
simple-requirement
type-requirement
compound-requirement
nested-requirement
simple-requirement:
expression ;
type-requirement:
typename nested-name-specifieropt type-name ;
compound-requirement:
{ expression } noexceptopt return-type-requirementopt ;
return-type-requirement:
trailing-return-type
-> cv-qualifier-seqopt constrained-parameter cv-qualifier-seqopt
abstract-declaratoropt
nested-requirement:
requires constraint-expression ;
postfix-expression:
primary-expression
postfix-expression [ expr-or-braced-init-list ]
postfix-expression ( expression-listopt )
simple-type-specifier ( expression-listopt )
typename-specifier ( expression-listopt )
simple-type-specifier braced-init-list
typename-specifier braced-init-list
postfix-expression . templateopt id-expression
postfix-expression -> templateopt id-expression
postfix-expression . pseudo-destructor-name
postfix-expression -> pseudo-destructor-name
postfix-expression ++
postfix-expression --
dynamic_cast < type-id > ( expression )
static_cast < type-id > ( expression )
reinterpret_cast < type-id > ( expression )
const_cast < type-id > ( expression )
typeid ( expression )
typeid ( type-id )
expression-list:
initializer-list
pseudo-destructor-name:
nested-name-specifieropt type-name :: ~ type-name
nested-name-specifier template simple-template-id :: ~ type-name
~ type-name
~ decltype-specifier
§ A.4
1265
unary-expression:
postfix-expression
++ cast-expression
-- cast-expression
unary-operator cast-expression
sizeof unary-expression
sizeof ( type-id )
sizeof ... ( identifier )
alignof ( type-id )
noexcept-expression
new-expression
delete-expression
unary-operator: one of
* & + - ! ~
new-expression:
::opt new new-placementopt new-type-id new-initializeropt
::opt new new-placementopt ( type-id ) new-initializeropt
new-placement:
( expression-list )
new-type-id:
type-specifier-seq new-declaratoropt
new-declarator:
ptr-operator new-declaratoropt
noptr-new-declarator
noptr-new-declarator:
[ expression ] attribute-specifier-seqopt
noptr-new-declarator [ constant-expression ] attribute-specifier-seqopt
new-initializer:
( expression-listopt )
braced-init-list
delete-expression:
::opt delete cast-expression
::opt delete [ ] cast-expression
noexcept-expression:
noexcept ( expression )
cast-expression:
unary-expression
( type-id ) cast-expression
pm-expression:
cast-expression
pm-expression .* cast-expression
pm-expression ->* cast-expression
multiplicative-expression:
pm-expression
multiplicative-expression * pm-expression
multiplicative-expression / pm-expression
multiplicative-expression % pm-expression
additive-expression:
multiplicative-expression
additive-expression + multiplicative-expression
additive-expression - multiplicative-expression
shift-expression:
additive-expression
shift-expression << additive-expression
shift-expression >> additive-expression
compare-expression:
shift-expression
compare-expression <=> shift-expression
§ A.4
1266
relational-expression:
compare-expression
relational-expression < compare-expression
relational-expression > compare-expression
relational-expression <= compare-expression
relational-expression >= compare-expression
equality-expression:
relational-expression
equality-expression == relational-expression
equality-expression != relational-expression
and-expression:
equality-expression
and-expression & equality-expression
exclusive-or-expression:
and-expression
exclusive-or-expression ^ and-expression
inclusive-or-expression:
exclusive-or-expression
inclusive-or-expression | exclusive-or-expression
logical-and-expression:
inclusive-or-expression
logical-and-expression && inclusive-or-expression
logical-or-expression:
logical-and-expression
logical-or-expression || logical-and-expression
conditional-expression:
logical-or-expression
logical-or-expression ? expression : assignment-expression
throw-expression:
throw assignment-expressionopt
assignment-expression:
conditional-expression
logical-or-expression assignment-operator initializer-clause
throw-expression
assignment-operator: one of
= *= /= %= += -= >>= <<= &= ^= |=
expression:
assignment-expression
expression , assignment-expression
constant-expression:
conditional-expression
A.5
Statements
[gram.stmt]
statement:
labeled-statement
attribute-specifier-seqopt expression-statement
attribute-specifier-seqopt compound-statement
attribute-specifier-seqopt selection-statement
attribute-specifier-seqopt iteration-statement
attribute-specifier-seqopt jump-statement
declaration-statement
attribute-specifier-seqopt try-block
init-statement:
expression-statement
simple-declaration
condition:
expression
attribute-specifier-seqopt decl-specifier-seq declarator brace-or-equal-initializer
§ A.5
1267
labeled-statement:
attribute-specifier-seqopt identifier : statement
attribute-specifier-seqopt case constant-expression : statement
attribute-specifier-seqopt default : statement
expression-statement:
expressionopt ;
compound-statement:
{ statement-seqopt }
statement-seq:
statement
statement-seq statement
selection-statement:
if constexpropt ( init-statementopt condition ) statement
if constexpropt ( init-statementopt condition ) statement else statement
switch ( init-statementopt condition ) statement
iteration-statement:
while ( condition ) statement
do statement while ( expression ) ;
for ( init-statement conditionopt ; expressionopt ) statement
for ( init-statementopt for-range-declaration : for-range-initializer ) statement
for-range-declaration:
attribute-specifier-seqopt decl-specifier-seq declarator
attribute-specifier-seqopt decl-specifier-seq ref-qualifieropt
[ identifier-list ]
for-range-initializer:
expr-or-braced-init-list
jump-statement:
break ;
continue ;
return expr-or-braced-init-listopt
;
goto identifier ;
declaration-statement:
block-declaration
A.6
Declarations
[gram.dcl]
declaration-seq:
declaration
declaration-seq declaration
declaration:
block-declaration
nodeclspec-function-declaration
function-definition
template-declaration
deduction-guide
explicit-instantiation
explicit-specialization
linkage-specification
namespace-definition
empty-declaration
attribute-declaration
block-declaration:
simple-declaration
asm-definition
namespace-alias-definition
using-declaration
using-directive
static_assert-declaration
alias-declaration
opaque-enum-declaration
§ A.6
1268
nodeclspec-function-declaration:
attribute-specifier-seqopt declarator ;
alias-declaration:
using identifier attribute-specifier-seqopt = defining-type-id ;
simple-declaration:
decl-specifier-seq init-declarator-listopt ;
attribute-specifier-seq decl-specifier-seq init-declarator-list ;
attribute-specifier-seqopt decl-specifier-seq ref-qualifieropt [ identifier-list ] initializer ;
static_assert-declaration:
static_assert ( constant-expression ) ;
static_assert ( constant-expression , string-literal ) ;
empty-declaration:
;
attribute-declaration:
attribute-specifier-seq ;
decl-specifier:
storage-class-specifier
defining-type-specifier
function-specifier
friend
typedef
constexpr
inline
decl-specifier-seq:
decl-specifier attribute-specifier-seqopt
decl-specifier decl-specifier-seq
storage-class-specifier:
static
thread_local
extern
mutable
function-specifier:
virtual
explicit
typedef-name:
identifier
type-specifier:
simple-type-specifier
elaborated-type-specifier
typename-specifier
cv-qualifier
type-specifier-seq:
type-specifier attribute-specifier-seqopt
type-specifier type-specifier-seq
defining-type-specifier:
type-specifier
class-specifier
enum-specifier
defining-type-specifier-seq:
defining-type-specifier attribute-specifier-seqopt
defining-type-specifier defining-type-specifier-seq
§ A.6
1269
simple-type-specifier:
nested-name-specifieropt type-name
nested-name-specifier template simple-template-id
nested-name-specifieropt template-name
char
char16_t
char32_t
wchar_t
bool
short
int
long
signed
unsigned
float
double
void
auto
decltype-specifier
type-name:
class-name
enum-name
typedef-name
simple-template-id
decltype-specifier:
decltype ( expression )
decltype ( auto )
elaborated-type-specifier:
class-key attribute-specifier-seqopt nested-name-specifieropt
identifier
class-key simple-template-id
class-key nested-name-specifier templateopt simple-template-id
enum nested-name-specifieropt identifier
enum-name:
identifier
enum-specifier:
enum-head { enumerator-listopt }
enum-head { enumerator-list , }
enum-head:
enum-key attribute-specifier-seqopt enum-head-nameopt enum-baseopt
enum-head-name:
nested-name-specifieropt identifier
opaque-enum-declaration:
enum-key attribute-specifier-seqopt nested-name-specifieropt identifier enum-baseopt
;
enum-key:
enum
enum class
enum struct
enum-base:
: type-specifier-seq
enumerator-list:
enumerator-definition
enumerator-list , enumerator-definition
enumerator-definition:
enumerator
enumerator = constant-expression
enumerator:
identifier attribute-specifier-seqopt
§ A.6
1270
namespace-name:
identifier
namespace-alias
namespace-definition:
named-namespace-definition
unnamed-namespace-definition
nested-namespace-definition
named-namespace-definition:
inlineopt namespace attribute-specifier-seqopt identifier { namespace-body }
unnamed-namespace-definition:
inlineopt namespace attribute-specifier-seqopt { namespace-body }
nested-namespace-definition:
namespace enclosing-namespace-specifier :: identifier { namespace-body }
enclosing-namespace-specifier:
identifier
enclosing-namespace-specifier :: identifier
namespace-body:
declaration-seqopt
namespace-alias:
identifier
namespace-alias-definition:
namespace identifier = qualified-namespace-specifier ;
qualified-namespace-specifier:
nested-name-specifieropt namespace-name
using-declaration:
using using-declarator-list ;
using-declarator-list:
using-declarator ...opt
using-declarator-list , using-declarator ...opt
using-declarator:
typenameopt nested-name-specifier unqualified-id
using-directive:
attribute-specifier-seqopt using namespace nested-name-specifieropt
namespace-name ;
asm-definition:
attribute-specifier-seqopt asm ( string-literal )
;
linkage-specification:
extern string-literal { declaration-seqopt }
extern string-literal declaration
attribute-specifier-seq:
attribute-specifier-seqopt attribute-specifier
attribute-specifier:
[ [ attribute-using-prefixopt attribute-list ] ]
alignment-specifier
alignment-specifier:
alignas ( type-id ...opt )
alignas ( constant-expression ...opt )
attribute-using-prefix:
using attribute-namespace :
attribute-list:
attributeopt
attribute-list , attributeopt
attribute ...
attribute-list , attribute ...
attribute:
attribute-token attribute-argument-clauseopt
§ A.6
1271
attribute-token:
identifier
attribute-scoped-token
attribute-scoped-token:
attribute-namespace :: identifier
attribute-namespace:
identifier
attribute-argument-clause:
( balanced-token-seqopt )
balanced-token-seq:
balanced-token
balanced-token-seq balanced-token
balanced-token:
( balanced-token-seqopt )
[ balanced-token-seqopt ]
{ balanced-token-seqopt }
any token other than a parenthesis, a bracket, or a brace
A.7
Declarators
[gram.decl]
init-declarator-list:
init-declarator
init-declarator-list , init-declarator
init-declarator:
declarator initializeropt
declarator requires-clause
declarator:
ptr-declarator
noptr-declarator parameters-and-qualifiers trailing-return-type
ptr-declarator:
noptr-declarator
ptr-operator ptr-declarator
noptr-declarator:
declarator-id attribute-specifier-seqopt
noptr-declarator parameters-and-qualifiers
noptr-declarator [ constant-expressionopt ] attribute-specifier-seqopt
( ptr-declarator )
parameters-and-qualifiers:
( parameter-declaration-clause ) cv-qualifier-seqopt
ref-qualifieropt noexcept-specifieropt attribute-specifier-seqopt
trailing-return-type:
-> type-id
ptr-operator:
* attribute-specifier-seqopt cv-qualifier-seqopt
& attribute-specifier-seqopt
&& attribute-specifier-seqopt
nested-name-specifier * attribute-specifier-seqopt cv-qualifier-seqopt
cv-qualifier-seq:
cv-qualifier cv-qualifier-seqopt
cv-qualifier:
const
volatile
ref-qualifier:
&
&&
declarator-id:
...opt id-expression
§ A.7
1272
type-id:
type-specifier-seq abstract-declaratoropt
defining-type-id:
defining-type-specifier-seq abstract-declaratoropt
abstract-declarator:
ptr-abstract-declarator
noptr-abstract-declaratoropt parameters-and-qualifiers trailing-return-type
abstract-pack-declarator
ptr-abstract-declarator:
noptr-abstract-declarator
ptr-operator ptr-abstract-declaratoropt
noptr-abstract-declarator:
noptr-abstract-declaratoropt parameters-and-qualifiers
noptr-abstract-declaratoropt [ constant-expressionopt ] attribute-specifier-seqopt
( ptr-abstract-declarator )
abstract-pack-declarator:
noptr-abstract-pack-declarator
ptr-operator abstract-pack-declarator
noptr-abstract-pack-declarator:
noptr-abstract-pack-declarator parameters-and-qualifiers
noptr-abstract-pack-declarator [ constant-expressionopt ] attribute-specifier-seqopt
parameter-declaration-clause:
parameter-declaration-listopt ...opt
parameter-declaration-list , ...
parameter-declaration-list:
parameter-declaration
parameter-declaration-list , parameter-declaration
parameter-declaration:
attribute-specifier-seqopt decl-specifier-seq declarator
attribute-specifier-seqopt decl-specifier-seq declarator = initializer-clause
attribute-specifier-seqopt decl-specifier-seq abstract-declaratoropt
attribute-specifier-seqopt decl-specifier-seq abstract-declaratoropt = initializer-clause
function-definition:
attribute-specifier-seqopt decl-specifier-seqopt declarator virt-specifier-seqopt function-body
attribute-specifier-seqopt decl-specifier-seqopt declarator requires-clause function-body
function-body:
ctor-initializeropt compound-statement
function-try-block
= default ;
= delete ;
initializer:
brace-or-equal-initializer
( expression-list )
brace-or-equal-initializer:
= initializer-clause
braced-init-list
initializer-clause:
assignment-expression
braced-init-list
braced-init-list:
{ initializer-list ,opt }
{ designated-initializer-list ,opt }
{ }
initializer-list:
initializer-clause ...opt
initializer-list , initializer-clause ...opt
§ A.7
1273
designated-initializer-list:
designated-initializer-clause
designated-initializer-list , designated-initializer-clause
designated-initializer-clause:
designator brace-or-equal-initializer
designator:
. identifier
expr-or-braced-init-list:
expression
braced-init-list
A.8
Classes
[gram.class]
class-name:
identifier
simple-template-id
class-specifier:
class-head { member-specificationopt }
class-head:
class-key attribute-specifier-seqopt class-head-name class-virt-specifieropt
base-clauseopt
class-key attribute-specifier-seqopt base-clauseopt
class-head-name:
nested-name-specifieropt class-name
class-virt-specifier:
final
class-key:
class
struct
union
member-specification:
member-declaration member-specificationopt
access-specifier : member-specificationopt
member-declaration:
attribute-specifier-seqopt decl-specifier-seqopt member-declarator-listopt
;
function-definition
using-declaration
static_assert-declaration
template-declaration
deduction-guide
alias-declaration
empty-declaration
member-declarator-list:
member-declarator
member-declarator-list , member-declarator
member-declarator:
declarator virt-specifier-seqopt pure-specifieropt
declarator requires-clause
declarator brace-or-equal-initializeropt
identifieropt attribute-specifier-seqopt : constant-expression brace-or-equal-initializeropt
virt-specifier-seq:
virt-specifier
virt-specifier-seq virt-specifier
virt-specifier:
override
final
pure-specifier:
= 0
§ A.8
1274
A.9
Derived classes
[gram.derived]
base-clause:
: base-specifier-list
base-specifier-list:
base-specifier ...opt
base-specifier-list , base-specifier ...opt
base-specifier:
attribute-specifier-seqopt class-or-decltype
attribute-specifier-seqopt virtual access-specifieropt
class-or-decltype
attribute-specifier-seqopt access-specifier virtualopt
class-or-decltype
class-or-decltype:
nested-name-specifieropt class-name
nested-name-specifier template simple-template-id
decltype-specifier
access-specifier:
private
protected
public
A.10
Special member functions
[gram.special]
conversion-function-id:
operator conversion-type-id
conversion-type-id:
type-specifier-seq conversion-declaratoropt
conversion-declarator:
ptr-operator conversion-declaratoropt
ctor-initializer:
: mem-initializer-list
mem-initializer-list:
mem-initializer ...opt
mem-initializer-list , mem-initializer ...opt
mem-initializer:
mem-initializer-id ( expression-listopt )
mem-initializer-id braced-init-list
mem-initializer-id:
class-or-decltype
identifier
A.11
Overloading
[gram.over]
operator-function-id:
operator operator
operator: one of
new
delete new[]
delete[] ( )
[]
->
->*
~
!
+
-
/
%
^
&
|
=
+=
-=
*=
/=
%=
^=
&=
|=
==
!=
<
>
<=
>=
<=>
&&
||
<<
>>
<<=
>>=
++
--
,
literal-operator-id:
operator string-literal identifier
operator user-defined-string-literal
A.12
Templates
[gram.temp]
template-declaration:
template-head declaration
template-head concept-definition
template-head:
template < template-parameter-list > requires-clauseopt
§ A.12
1275
template-parameter-list:
template-parameter
template-parameter-list , template-parameter
requires-clause:
requires constraint-logical-or-expression
constraint-logical-or-expression:
constraint-logical-and-expression
constraint-logical-or-expression || constraint-logical-and-expression
constraint-logical-and-expression:
primary-expression
constraint-logical-and-expression && primary-expression
concept-definition:
concept concept-name = constraint-expression ;
concept-name:
identifier
template-parameter:
type-parameter
parameter-declaration
constrained-parameter
type-parameter:
type-parameter-key ...opt identifieropt
type-parameter-key identifieropt = type-id
template-head type-parameter-key ...opt identifieropt
template-head type-parameter-key identifieropt = id-expression
type-parameter-key:
class
typename
constrained-parameter:
qualified-concept-name ... identifieropt
qualified-concept-name identifieropt default-template-argumentopt
qualified-concept-name:
nested-name-specifieropt concept-name
nested-name-specifieropt partial-concept-id
partial-concept-id:
concept-name < template-argument-listopt >
default-template-argument:
= type-id
= id-expression
= initializer-clause
simple-template-id:
template-name < template-argument-listopt >
template-id:
simple-template-id
operator-function-id < template-argument-listopt >
literal-operator-id < template-argument-listopt >
template-name:
identifier
template-argument-list:
template-argument ...opt
template-argument-list , template-argument ...opt
template-argument:
constant-expression
type-id
id-expression
constraint-expression:
logical-or-expression
§ A.12
1276
typename-specifier:
typename nested-name-specifier identifier
typename nested-name-specifier templateopt simple-template-id
explicit-instantiation:
externopt template declaration
explicit-specialization:
template < > declaration
deduction-guide:
explicitopt template-name ( parameter-declaration-clause ) -> simple-template-id ;
A.13
Exception handling
[gram.except]
try-block:
try compound-statement handler-seq
function-try-block:
try ctor-initializeropt compound-statement handler-seq
handler-seq:
handler handler-seqopt
handler:
catch ( exception-declaration ) compound-statement
exception-declaration:
attribute-specifier-seqopt type-specifier-seq declarator
attribute-specifier-seqopt type-specifier-seq abstract-declaratoropt
noexcept-specifier:
noexcept ( constant-expression )
noexcept
throw ( )
A.14
Preprocessing directives
[gram.cpp]
preprocessing-file:
groupopt
group:
group-part
group group-part
group-part:
control-line
if-section
text-line
# conditionally-supported-directive
control-line:
# include
pp-tokens new-line
# define
identifier replacement-list new-line
# define
identifier lparen identifier-listopt ) replacement-list new-line
# define
identifier lparen ... ) replacement-list new-line
# define
identifier lparen identifier-list , ...
) replacement-list new-line
# undef
identifier new-line
# line
pp-tokens new-line
# error
pp-tokensopt new-line
# pragma
pp-tokensopt new-line
# new-line
if-section:
if-group elif-groupsopt else-groupopt endif-line
if-group:
# if
constant-expression new-line groupopt
# ifdef
identifier new-line groupopt
# ifndef
identifier new-line groupopt
§ A.14
1277
elif-groups:
elif-group
elif-groups elif-group
elif-group:
# elif
constant-expression new-line groupopt
else-group:
# else
new-line groupopt
endif-line:
# endif
new-line
text-line:
pp-tokensopt new-line
conditionally-supported-directive:
pp-tokens new-line
lparen:
a ( character not immediately preceded by white-space
identifier-list:
identifier
identifier-list , identifier
replacement-list:
pp-tokensopt
pp-tokens:
preprocessing-token
pp-tokens preprocessing-token
new-line:
the new-line character
defined-macro-expression:
defined identifier
defined ( identifier )
h-preprocessing-token:
any preprocessing-token other than >
h-pp-tokens:
h-preprocessing-token
h-pp-tokens h-preprocessing-token
has-include-expression:
__has_include ( < h-char-sequence > )
__has_include ( " q-char-sequence " )
__has_include ( string-literal )
__has_include ( < h-pp-tokens > )
§ A.14
1278
Annex B
(informative)
Implementation quantities
[implimits]
1
Because computers are finite, C++ implementations are inevitably limited in the size of the programs
they can successfully process. Every implementation shall document those limitations where known. This
documentation may cite fixed limits where they exist, say how to compute variable limits as a function of
available resources, or say that fixed limits do not exist or are unknown.
2
The limits may constrain quantities that include those described below or others. The bracketed number
following each quantity is recommended as the minimum for that quantity. However, these quantities are
only guidelines and do not determine compliance.
(2.1)
Nesting levels of compound statements (9.3), iteration control structures (9.5), and selection control
structures (9.4) [256].
(2.2)
Nesting levels of conditional inclusion (19.1) [256].
(2.3)
Pointer (11.3.1), array (11.3.4), and function (11.3.5) declarators (in any combination) modifying a
class, arithmetic, or incomplete type in a declaration [256].
(2.4)
Nesting levels of parenthesized expressions (8.4.3) within a full-expression [256].
(2.5)
Number of characters in an internal identifier (5.10) or macro name (19.3) [1 024].
(2.6)
Number of characters in an external identifier (5.10, 6.5) [1 024].
(2.7)
External identifiers (6.5) in one translation unit [65 536].
(2.8)
Identifiers with block scope declared in one block (6.3.3) [1 024].
(2.9)
Structured bindings (11.5) introduced in one declaration [256].
(2.10)
Macro identifiers (19.3) simultaneously defined in one translation unit [65 536].
(2.11)
Parameters in one function definition (11.4.1) [256].
(2.12)
Arguments in one function call (8.5.1.2) [256].
(2.13)
Parameters in one macro definition (19.3) [256].
(2.14)
Arguments in one macro invocation (19.3) [256].
(2.15)
Characters in one logical source line (5.2) [65 536].
(2.16)
Characters in a string literal (5.13.5) (after concatenation (5.2)) [65 536].
(2.17)
Size of an object (6.6.2) [262 144].
(2.18)
Nesting levels for #include files (19.2) [256].
(2.19)
Case labels for a switch statement (9.4.2) (excluding those for any nested switch statements) [16 384].
(2.20)
Data members in a single class (12.2) [16 384].
(2.21)
Lambda-captures in one lambda-expression (8.4.5.2) [256].
(2.22)
Enumeration constants in a single enumeration (10.2) [4 096].
(2.23)
Levels of nested class definitions (12.2.5) in a single member-specification [256].
(2.24)
Functions registered by atexit() (21.5) [32].
(2.25)
Functions registered by at_quick_exit() (21.5) [32].
(2.26)
Direct and indirect base classes (Clause 13) [16 384].
(2.27)
Direct base classes for a single class (Clause 13) [1 024].
(2.28)
Members declared in a single class (12.2) [4 096].
(2.29)
Final overriding virtual functions in a class, accessible or not (13.3) [16 384].
(2.30)
Direct and indirect virtual bases of a class (13.1) [1 024].
Implementation quantities
1279
(2.31)
Static members of a class (12.2.3) [1 024].
(2.32)
Friend declarations in a class (14.3) [4 096].
(2.33)
Access control declarations in a class (14.1) [4 096].
(2.34)
Member initializers in a constructor definition (15.6.2) [6 144].
(2.35)
initializer-clauses in one braced-init-list (11.6) [16 384].
(2.36)
Scope qualifications of one identifier (8.4.4.2) [256].
(2.37)
Nested external specifications [1 024].
(2.38)
Recursive constexpr function invocations (10.1.5) [512].
(2.39)
Full-expressions evaluated within a core constant expression (8.6) [1 048 576].
(2.40)
Template arguments in a template declaration (17.1) [1 024].
(2.41)
Recursively nested template instantiations (17.8.1), including substitution during template argument
deduction (17.9.2) [1 024].
(2.42)
Handlers per try block (18.3) [256].
(2.43)
Number of placeholders (23.14.11.4) [10].
Implementation quantities
1280
Annex C
(informative)
Compatibility
[diff]
C.1
C++ and ISO C
[diff.iso]
1
This subclause lists the differences between C++ and ISO C, by the chapters of this document.
C.1.1
Clause 5: lexical conventions
[diff.lex]
1
Affected subclause: 5.11
Change: New Keywords
New keywords are added to C++; see 5.11.
Rationale: These keywords were added in order to implement the new semantics of C++.
Effect on original feature: Change to semantics of well-defined feature. Any ISO C programs that used
any of these keywords as identifiers are not valid C++ programs.
Difficulty of converting: Syntactic transformation. Converting one specific program is easy. Converting a
large collection of related programs takes more work.
How widely used: Common.
2
Affected subclause: 5.13.3
Change: Type of character literal is changed from int to char.
Rationale: This is needed for improved overloaded function argument type matching. For example:
int function( int i );
int function( char c );
function( ’x’ );
It is preferable that this call match the second version of function rather than the first.
Effect on original feature: Change to semantics of well-defined feature. ISO C programs which depend on
sizeof(’x’) == sizeof(int)
will not work the same as C++ programs.
Difficulty of converting: Simple.
How widely used: Programs which depend upon sizeof(’x’) are probably rare.
3
Affected subclause: 5.13.5
Change: String literals made const.
The type of a string literal is changed from “array of char” to “array of const char”. The type of a char16_t
string literal is changed from “array of some-integer-type” to “array of const char16_t”. The type of a
char32_t string literal is changed from “array of some-integer-type” to “array of const char32_t”. The
type of a wide string literal is changed from “array of wchar_t” to “array of const wchar_t”.
Rationale: This avoids calling an inappropriate overloaded function, which might expect to be able to
modify its argument.
Effect on original feature: Change to semantics of well-defined feature.
Difficulty of converting: Syntactic transformation. The fix is to add a cast:
char* p = "abc";
// valid in C, invalid in C++
void f(char*) {
char* p = (char*)"abc";
// OK: cast added
f(p);
f((char*)"def");
// OK: cast added
}
How widely used: Programs that have a legitimate reason to treat string literals as pointers to potentially
modifiable memory are probably rare.
§ C.1.1
1281

 

 

 

 

 

 

 

Content      ..     41      42      43      44     ..