Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/compatibility.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@
\grammarterm{pp-number} can contain \tcode{p} \grammarterm{sign} and
\tcode{P} \grammarterm{sign}.
\rationale
Necessary to enable hexadecimal floating-point literals.
Necessary to enable \grammarterm{hexadecimal-floating-point-literal}s.
\effect
Valid \CppXIV{} code may fail to compile or produce different results in
this International Standard. Specifically, character sequences like \tcode{0p+0}
Expand Down
211 changes: 117 additions & 94 deletions source/lex.tex
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,14 @@
\pnum
\begin{example}
The program fragment \tcode{0xe+foo} is parsed as a
preprocessing number token (one that is not a valid integer or floating-point
literal token), even though a parse as three preprocessing tokens
preprocessing number token (one that is not a valid
\grammarterm{integer-literal} or \grammarterm{floating-point-literal} token),
even though a parse as three preprocessing tokens
\tcode{0xe}, \tcode{+}, and \tcode{foo} might produce a valid expression (for example,
if \tcode{foo} were a macro defined as \tcode{1}). Similarly, the
program fragment \tcode{1E1} is parsed as a preprocessing number (one
that is a valid floating-point literal token), whether or not \tcode{E} is a
macro name.
that is a valid \grammarterm{floating-point-literal} token),
whether or not \tcode{E} is a macro name.
\end{example}

\pnum
Expand Down Expand Up @@ -583,14 +584,15 @@
\end{bnf}

\pnum
Preprocessing number tokens lexically include all integer literal
tokens\iref{lex.icon} and all floating-point literal
tokens\iref{lex.fcon}.
Preprocessing number tokens lexically include
all \grammarterm{integer-literal} tokens\iref{lex.icon} and
all \grammarterm{floating-point-literal} tokens\iref{lex.fcon}.

\pnum
A preprocessing number does not have a type or a value; it acquires both
after a successful conversion to an integer literal token or a floating-point literal
token.%
after a successful conversion to
an \grammarterm{integer-literal} token or
a \grammarterm{floating-point-literal} token.%
\indextext{number!preprocessing|)}

\rSec1[lex.name]{Identifiers}
Expand Down Expand Up @@ -1033,28 +1035,38 @@
\indextext{literal!\idxcode{unsigned}}%
\indextext{literal!\idxcode{long}}%
\indextext{literal!base of integer}%
An \defnx{integer literal}{literal!integer} is a sequence of digits that has no period
or exponent part, with optional separating single quotes that are ignored
when determining its value. An integer literal may have a prefix that specifies
its base and a suffix that specifies its type. The lexically first digit
of the sequence of digits is the most significant.
A \defnx{binary integer literal}{literal!binary} (base two) begins with
\tcode{0b} or \tcode{0B} and consists of a sequence of binary digits.
An \defnx{octal integer literal}{literal!octal}
(base eight) begins with the digit \tcode{0} and consists of a
sequence of octal digits.\footnote{The digits \tcode{8} and \tcode{9} are not octal digits. }
A \defnx{decimal integer literal}{literal!decimal}
(base ten) begins with a digit other than \tcode{0} and
consists of a sequence of decimal digits.
A \defnx{hexadecimal integer literal}{literal!hexadecimal}
(base sixteen) begins with
\tcode{0x} or \tcode{0X} and consists of a sequence of hexadecimal
digits, which include the decimal digits and the letters \tcode{a}
through \tcode{f} and \tcode{A} through \tcode{F} with decimal values
ten through fifteen.
In an \grammarterm{integer-literal},
the sequence of
\grammarterm{binary-digit}s,
\grammarterm{octal-digit}s,
\grammarterm{digit}s, or
\grammarterm{hexadecimal-digit}s
is interpreted as a base $N$ integer as shown in table \tref{lex.icon.base};
the lexically first digit of the sequence of digits is the most significant.
\begin{note}
The prefix and any optional separating single quotes are ignored
when determining the value.
\end{note}

\begin{simpletypetable}
{Base of \grammarterm{integer-literal}{s}}
{lex.icon.base}
{lr}
\topline
\lhdr{Kind of \grammarterm{integer-literal}} & \rhdr{base $N$} \\ \capsep
\grammarterm{binary-literal} & 2 \\
\grammarterm{octal-literal} & 8 \\
\grammarterm{decimal-literal} & 10 \\
\grammarterm{hexadecimal-literal} & 16 \\
\end{simpletypetable}

\pnum
The \grammarterm{hexadecimal-digit}s
\tcode{a} through \tcode{f} and \tcode{A} through \tcode{F}
have decimal values ten through fifteen.
\begin{example}
The number twelve can be written \tcode{12}, \tcode{014},
\tcode{0XC}, or \tcode{0b1100}. The integer literals \tcode{1048576},
\tcode{0XC}, or \tcode{0b1100}. The \grammarterm{integer-literal}s \tcode{1048576},
\tcode{1'048'576}, \tcode{0X100000}, \tcode{0x10'0000}, and
\tcode{0'004'000'000} all have the same value.
\end{example}
Expand All @@ -1068,18 +1080,19 @@
\indextext{suffix!\idxcode{U}}%
\indextext{suffix!\idxcode{l}}%
\indextext{suffix!\idxcode{u}}%
The type of an integer literal is the first of the corresponding list
in \tref{lex.icon.type} in which its value can be
represented.
The type of an \grammarterm{integer-literal} is
the first type in the list in \tref{lex.icon.type}
corresponding to its optional \grammarterm{integer-suffix}
in which its value can be represented.
An \grammarterm{integer-literal} is a prvalue.

\enlargethispage{\baselineskip}%
\begin{LongTable}{Types of integer literals}{lex.icon.type}{l|l|l}
\begin{LongTable}{Types of \grammarterm{integer-literal}s}{lex.icon.type}{l|l|l}
\\ \topline
\lhdr{Suffix} & \chdr{Decimal literal} & \rhdr{Binary, octal, or hexadecimal literal} \\ \capsep
\lhdr{\grammarterm{integer-suffix}} & \chdr{\grammarterm{decimal-literal}} & \rhdr{\grammarterm{integer-literal} other than \grammarterm{decimal-literal}} \\ \capsep
\endfirsthead
\continuedcaption\\
\hline
\lhdr{Suffix} & \chdr{Decimal literal} & \rhdr{Binary, octal, or hexadecimal literal} \\ \capsep
\lhdr{\grammarterm{integer-suffix}} & \chdr{\grammarterm{decimal-literal}} & \rhdr{\grammarterm{integer-literal} other than \grammarterm{decimal-literal}} \\ \capsep
\endhead
none &
\tcode{int} &
Expand Down Expand Up @@ -1141,14 +1154,20 @@
\end{LongTable}

\pnum
If an integer literal cannot be represented by any type in its list and
an extended integer type\iref{basic.fundamental} can represent its value, it may have that
extended integer type. If all of the types in the list for the integer literal
are signed, the extended integer type shall be signed. If all of the
types in the list for the integer literal are unsigned, the extended integer
type shall be unsigned. If the list contains both signed and unsigned
types, the extended integer type may be signed or unsigned. A program is
ill-formed if one of its translation units contains an integer literal
If an \grammarterm{integer-literal}
cannot be represented by any type in its list and
an extended integer type\iref{basic.fundamental} can represent its value,
it may have that extended integer type.
If all of the types in the list for the \grammarterm{integer-literal}
are signed,
the extended integer type shall be signed.
If all of the types in the list for the \grammarterm{integer-literal}
are unsigned,
the extended integer type shall be unsigned.
If the list contains both signed and unsigned types,
the extended integer type may be signed or unsigned.
A program is ill-formed
if one of its translation units contains an \grammarterm{integer-literal}
that cannot be represented by any of the allowed types.

\rSec2[lex.ccon]{Character literals}
Expand Down Expand Up @@ -1454,64 +1473,68 @@
\end{bnf}

\pnum
\indextext{literal!floating-point}%
A floating-point literal consists of
an optional prefix specifying a base,
an integer part,
a radix point,
a fraction part,
\indextext{suffix!\idxcode{e}}%
\indextext{suffix!\idxcode{E}}%
\indextext{suffix!\idxcode{p}}%
\indextext{suffix!\idxcode{P}}%
an \tcode{e}, \tcode{E}, \tcode{p} or \tcode{P},
an optionally signed integer exponent, and
an optional type suffix.
The integer and fraction parts both consist of
a sequence of decimal (base ten) digits if there is no prefix, or
hexadecimal (base sixteen) digits if the prefix is \tcode{0x} or \tcode{0X}.
The floating-point literal is a \defnadj{decimal floating-point}{literal} in the former case and
a \defnadj{hexadecimal floating}{literal} in the latter case.
Optional separating single quotes in
a \grammarterm{digit-sequence} or \grammarterm{hexadecimal-digit-sequence}
are ignored when determining its value.
\begin{example}
The floating-point literals \tcode{1.602'176'565e-19} and \tcode{1.602176565e-19}
have the same value.
\end{example}
Either the integer part or the fraction part (not both) can be omitted.
Either the radix point or the letter \tcode{e} or \tcode{E} and
the exponent (not both) can be omitted from a decimal floating-point literal.
The radix point (but not the exponent) can be omitted
from a hexadecimal floating-point literal.
The integer part, the optional radix point, and the optional fraction part,
form the \defn{significand} of the floating-point literal.
In a decimal floating-point literal, the exponent, if present,
indicates the power of 10 by which the significand is to be scaled.
In a hexadecimal floating-point literal, the exponent
indicates the power of 2 by which the significand is to be scaled.
\begin{example}
The floating-point literals \tcode{49.625} and \tcode{0xC.68p+2} have the same value.
\end{example}
If the scaled value is in
the range of representable values for its type, the result is the scaled
value if representable, else the larger or smaller representable value
nearest the scaled value, chosen in an \impldef{choice of larger or smaller value of
floating-point literal} manner.
\indextext{literal!\idxcode{double}}%
The type of a floating-point literal is \tcode{double}
\indextext{literal!type of floating-point}%
unless explicitly specified by a suffix.
\indextext{literal!\idxcode{float}}%
\indextext{suffix!\idxcode{F}}%
\indextext{suffix!\idxcode{f}}%
The suffixes \tcode{f} and \tcode{F} specify \tcode{float},
\indextext{suffix!\idxcode{L}}%
\indextext{suffix!\idxcode{l}}%
\indextext{literal!\idxcode{long double}}%
the suffixes \tcode{l} and \tcode{L} specify \tcode{long}
\tcode{double}. If the scaled value is not in the range of representable
The type of a \grammarterm{floating-point-literal} is determined by
its \grammarterm{floating-point-suffix} as specified in \tref{lex.fcon.type}.
\begin{simpletypetable}
{Types of \grammarterm{floating-point-literal}{s}}
{lex.fcon.type}
{ll}
\topline
\lhdr{\grammarterm{floating-point-suffix}} & \rhdr{type} \\ \capsep
none & \keyword{double} \\
\tcode{f} or \tcode{F} & \keyword {float} \\
\tcode{l} or \tcode{L} & \keyword{long} \keyword{double} \\
\end{simpletypetable}

\pnum
\indextext{literal!floating-point}%
The \defn{significand} of a \grammarterm{floating-point-literal}
is the \grammarterm{fractional-constant} or \grammarterm{digit-sequence}
of a \grammarterm{decimal-floating-point-literal}
or the \grammarterm{hexadecimal-fractional-constant}
or \grammarterm{hexadecimal-digit-sequence}
of a \grammarterm{hexadecimal-floating-point-literal}.
In the significand,
the sequence of \grammarterm{digit}s or \grammarterm{hexadecimal-digit}s
and optional period are interpreted as a base $N$ real number $s$,
where $N$ is 10 for a \grammarterm{decimal-floating-point-literal} and
16 for a \grammarterm{hexadecimal-floating-point-literal}.
\begin{note}
Any optional separating single quotes are ignored when determining the value.
\end{note}
If an \grammarterm{exponent-part} or \grammarterm{binary-exponent-part}
is present,
the exponent $e$ of the \grammarterm{floating-point-literal}
is the result of interpreting
the sequence of an optional \grammarterm{sign} and the \grammarterm{digit}s
as a base 10 integer.
Otherwise, the exponent $e$ is 0.
The scaled value of the literal is
$s \times 10^e$ for a \grammarterm{decimal-floating-point-literal} and
$s \times 2^e$ for a \grammarterm{hexadecimal-floating-point-literal}.
\begin{example}
The \grammarterm{floating-point-literal}{s}
\tcode{49.625} and \tcode{0xC.68p+2} have the same value.
The \grammarterm{floating-point-literal}{s}
\tcode{1.602'176'565e-19} and \tcode{1.602176565e-19}
have the same value.
\end{example}

\pnum
If the scaled value is not in the range of representable
values for its type, the program is ill-formed.
Otherwise, the value of a \grammarterm{floating-point-literal}
is the scaled value if representable,
else the larger or smaller representable value nearest the scaled value,
chosen in an \impldef{choice of larger or smaller value of
\grammarterm{floating-point-literal}} manner.

\rSec2[lex.string]{String literals}

Expand Down
8 changes: 5 additions & 3 deletions source/time.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1886,14 +1886,16 @@
suffixes \tcode{h}, \tcode{min}, \tcode{s}, \tcode{ms}, \tcode{us}, \tcode{ns}
denote duration values of the corresponding types \tcode{hours}, \tcode{minutes},
\tcode{seconds}, \tcode{milliseconds}, \tcode{microseconds}, and \tcode{nanoseconds}
respectively if they are applied to integral literals.
respectively if they are applied to \grammarterm{integer-literal}{s}.

\pnum
If any of these suffixes are applied to a floating-point literal the result is a
If any of these suffixes are applied to a \grammarterm{floating-point-literal}
the result is a
\tcode{chrono::duration} literal with an unspecified floating-point representation.

\pnum
If any of these suffixes are applied to an integer literal and the resulting
If any of these suffixes are applied to an \grammarterm{integer-literal}
and the resulting
\tcode{chrono::duration} value cannot be represented in the result type because
of overflow, the program is ill-formed.

Expand Down