Skip to content

[CWG 4] P2796R0 CWG2521 User-defined literals and reserved identifiers #6121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2023
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
9 changes: 9 additions & 0 deletions source/future.tex
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@
It is possible that future versions of \Cpp{} will specify
that these implicit definitions are deleted\iref{dcl.fct.def.delete}.

\rSec1[depr.lit]{Literal operator function declarations using an identifier}

\pnum
A \grammarterm{literal-operator-id}\iref{over.literal} of the form
\begin{codeblock}
operator @\grammarterm{string-literal}@ @\grammarterm{identifier}@
\end{codeblock}
is deprecated.

\rSec1[depr.template.template]{\tcode{template} keyword before qualified names}

\pnum
Expand Down
34 changes: 18 additions & 16 deletions source/lex.tex
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,9 @@
\indextext{\idxcode{_}|see{character, underscore}}%
\indextext{character!underscore!in identifier}%
\indextext{reserved identifier}%
In addition, some identifiers are reserved for use by \Cpp{}
In addition, some identifiers
appearing as a \grammarterm{token} or \grammarterm{preprocessing-token}
are reserved for use by \Cpp{}
implementations and shall
not be used otherwise; no diagnostic is required.
\begin{itemize}
Expand Down Expand Up @@ -2257,19 +2259,19 @@
parameter type \tcode{unsigned long long}, the literal \placeholder{L} is treated as a call of
the form
\begin{codeblock}
operator "" @\placeholder{X}@(@\placeholder{n}@ULL)
operator ""@\placeholder{X}@(@\placeholder{n}@ULL)
\end{codeblock}
Otherwise, \placeholder{S} shall contain a raw literal operator
or a numeric literal operator template\iref{over.literal} but not both.
If \placeholder{S} contains a raw literal operator,
the literal \placeholder{L} is treated as a call of the form
\begin{codeblock}
operator "" @\placeholder{X}@("@\placeholder{n}@")
operator ""@\placeholder{X}@("@\placeholder{n}@")
\end{codeblock}
Otherwise (\placeholder{S} contains a numeric literal operator template),
\placeholder{L} is treated as a call of the form
\begin{codeblock}
operator "" @\placeholder{X}@<'@$c_1$@', '@$c_2$@', ... '@$c_k$@'>()
operator ""@\placeholder{X}@<'@$c_1$@', '@$c_2$@', ... '@$c_k$@'>()
\end{codeblock}
where \placeholder{n} is the source character sequence $c_1c_2...c_k$.
\begin{note}
Expand All @@ -2283,19 +2285,19 @@
with parameter type \tcode{long double}, the literal \placeholder{L} is treated as a call of
the form
\begin{codeblock}
operator "" @\placeholder{X}@(@\placeholder{f}@L)
operator ""@\placeholder{X}@(@\placeholder{f}@L)
\end{codeblock}
Otherwise, \placeholder{S} shall contain a raw literal operator
or a numeric literal operator template\iref{over.literal} but not both.
If \placeholder{S} contains a raw literal operator,
the \grammarterm{literal} \placeholder{L} is treated as a call of the form
\begin{codeblock}
operator "" @\placeholder{X}@("@\placeholder{f}@")
operator ""@\placeholder{X}@("@\placeholder{f}@")
\end{codeblock}
Otherwise (\placeholder{S} contains a numeric literal operator template),
\placeholder{L} is treated as a call of the form
\begin{codeblock}
operator "" @\placeholder{X}@<'@$c_1$@', '@$c_2$@', ... '@$c_k$@'>()
operator ""@\placeholder{X}@<'@$c_1$@', '@$c_2$@', ... '@$c_k$@'>()
\end{codeblock}
where \placeholder{f} is the source character sequence $c_1c_2...c_k$.
\begin{note}
Expand All @@ -2313,11 +2315,11 @@
a well-formed \grammarterm{template-argument},
the literal \placeholder{L} is treated as a call of the form
\begin{codeblock}
operator "" @\placeholder{X}@<@\placeholder{str}{}@>()
operator ""@\placeholder{X}@<@\placeholder{str}{}@>()
\end{codeblock}
Otherwise, the literal \placeholder{L} is treated as a call of the form
\begin{codeblock}
operator "" @\placeholder{X}@(@\placeholder{str}{}@, @\placeholder{len}{}@)
operator ""@\placeholder{X}@(@\placeholder{str}{}@, @\placeholder{len}{}@)
\end{codeblock}

\pnum
Expand All @@ -2328,19 +2330,19 @@
literal \placeholder{L} is treated as a call
of the form
\begin{codeblock}
operator "" @\placeholder{X}@(@\placeholder{ch}{}@)
operator ""@\placeholder{X}@(@\placeholder{ch}{}@)
\end{codeblock}

\pnum
\begin{example}
\begin{codeblock}
long double operator "" _w(long double);
std::string operator "" _w(const char16_t*, std::size_t);
unsigned operator "" _w(const char*);
long double operator ""_w(long double);
std::string operator ""_w(const char16_t*, std::size_t);
unsigned operator ""_w(const char*);
int main() {
1.2_w; // calls \tcode{operator "" _w(1.2L)}
u"one"_w; // calls \tcode{operator "" _w(u"one", 3)}
12_w; // calls \tcode{operator "" _w("12")}
1.2_w; // calls \tcode{operator ""_w(1.2L)}
u"one"_w; // calls \tcode{operator ""_w(u"one", 3)}
12_w; // calls \tcode{operator ""_w("12")}
"two"_w; // error: no applicable literal operator
}
\end{codeblock}
Expand Down
4 changes: 4 additions & 0 deletions source/lib-intro.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3154,6 +3154,10 @@

\pnum
Literal suffix identifiers\iref{over.literal} that do not start with an underscore are reserved for future standardization.
Literal suffix identifiers that contain a double underscore
\tcode{\unun}
\indextext{character!underscore}%
are reserved for use by \Cpp{} implementations.

\rSec3[alt.headers]{Headers}

Expand Down
17 changes: 9 additions & 8 deletions source/overloading.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3934,6 +3934,7 @@
The \grammarterm{ud-suffix} of the \grammarterm{user-defined-string-literal} or
the \grammarterm{identifier} in a \grammarterm{literal-operator-id} is called a
\defnx{literal suffix identifier}{literal!suffix identifier}.
The first form of \grammarterm{literal-operator-id} is deprecated.
Some literal suffix identifiers are reserved for future standardization;
see~\ref{usrlit.suffix}. A declaration whose \grammarterm{literal-operator-id} uses
such a literal suffix identifier is ill-formed, no diagnostic required.
Expand Down Expand Up @@ -4008,19 +4009,19 @@
\pnum
\begin{example}
\begin{codeblock}
void operator "" _km(long double); // OK
string operator "" _i18n(const char*, std::size_t); // OK
template <char...> double operator "" _\u03C0(); // OK, UCN for lowercase pi
void operator ""_km(long double); // OK
string operator "" _i18n(const char*, std::size_t); // OK, deprecated
template <char...> double operator ""_\u03C0(); // OK, UCN for lowercase pi
float operator ""_e(const char*); // OK
float operator ""E(const char*); // ill-formed, no diagnostic required:
// reserved literal suffix\iref{usrlit.suffix,lex.ext}
double operator""_Bq(long double); // OK, does not use the reserved \grammarterm{identifier} \tcode{_Bq}\iref{lex.name}
double operator"" _Bq(long double); // ill-formed, no diagnostic required:
// uses the reserved \grammarterm{identifier} \tcode{_Bq}\iref{lex.name}
float operator " " B(const char*); // error: non-empty \grammarterm{string-literal}
string operator "" 5X(const char*, std::size_t); // error: invalid literal suffix identifier
double operator "" _miles(double); // error: invalid \grammarterm{parameter-declaration-clause}
template <char...> int operator "" _j(const char*); // error: invalid \grammarterm{parameter-declaration-clause}
extern "C" void operator "" _m(long double); // error: C language linkage
float operator " "B(const char*); // error: non-empty \grammarterm{string-literal}
string operator ""5X(const char*, std::size_t); // error: invalid literal suffix identifier
double operator ""_miles(double); // error: invalid \grammarterm{parameter-declaration-clause}
template <char...> int operator ""_j(const char*); // error: invalid \grammarterm{parameter-declaration-clause}
extern "C" void operator ""_m(long double); // error: C language linkage
\end{codeblock}
\end{example}