Skip to content

P2893R3 Variadic friends #6896

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
Apr 15, 2024
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
53 changes: 41 additions & 12 deletions source/classes.tex
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@
\nontermdef{member-declaration}\br
\opt{attribute-specifier-seq} \opt{decl-specifier-seq} \opt{member-declarator-list} \terminal{;}\br
function-definition\br
friend-type-declaration\br
using-declaration\br
using-enum-declaration\br
static_assert-declaration\br
Expand Down Expand Up @@ -504,6 +505,24 @@
\terminal{=} \terminal{0}
\end{bnf}

\begin{bnf}
\nontermdef{friend-type-declaration}\br
\keyword{friend} friend-type-specifier-list \terminal{;}
\end{bnf}

\begin{bnf}
\nontermdef{friend-type-specifier-list}\br
friend-type-specifier \opt{\terminal{...}}\br
friend-type-specifier-list \terminal{,} friend-type-specifier \opt{\terminal{...}}
\end{bnf}

\begin{bnf}
\nontermdef{friend-type-specifier}\br
simple-type-specifier\br
elaborated-type-specifier\br
typename-specifier
\end{bnf}

\pnum
In the absence of a \grammarterm{virt-specifier-seq},
the token sequence \tcode{= 0} is treated as a \grammarterm{pure-specifier}
Expand Down Expand Up @@ -623,6 +642,11 @@
or if $P$ is in a complete-class context of \tcode{C}.
Otherwise, \tcode{C} is incomplete at $P$.

\pnum
If a \grammarterm{member-declaration} matches
the syntactic requirements of \grammarterm{friend-type-declaration},
it is a \grammarterm{friend-type-declaration}.

\pnum
In a \grammarterm{member-declarator},
an \tcode{=} immediately following the \grammarterm{declarator}
Expand Down Expand Up @@ -4787,27 +4811,22 @@

\pnum
A friend declaration that does not declare a function
shall have one of the following forms:

\begin{ncsimplebnf}
\keyword{friend} elaborated-type-specifier \terminal{;}\br
\keyword{friend} simple-type-specifier \terminal{;}\br
\keyword{friend} typename-specifier \terminal{;}
\end{ncsimplebnf}
shall be a \grammarterm{friend-type-declaration}.

\begin{note}
A friend declaration can be the
\grammarterm{declaration} in
a \grammarterm{template-declaration}\iref{temp.pre,temp.friend}.
\end{note}
If the
type specifier in a friend declaration designates a (possibly
If a \grammarterm{friend-type-specifier} in a friend declaration
designates a (possibly
cv-qualified) class type, that class is declared as a friend; otherwise, the
friend declaration is ignored.
\grammarterm{friend-type-specifier} is ignored.
\begin{example}
\begin{codeblock}
class C;
typedef C Ct;
class E;

class X1 {
friend C; // OK, \tcode{class C} is a friend
Expand All @@ -4819,12 +4838,22 @@
friend class D; // OK, elaborated-type-specifier declares new class
};

template <typename T> class R {
friend T;
template <typename ... Ts> class R {
friend Ts...;
};

template <class... Ts, class... Us>
class R<R<Ts...>, R<Us...>> {
friend Ts::Nested..., Us...;
};

R<C> rc; // \tcode{class C} is a friend of \tcode{R<C>}
R<C, E> rce; // classes \tcode{C} and \tcode{E} are friends of \tcode{R<C, E>}
R<int> Ri; // OK, \tcode{"friend int;"} is ignored

struct E { struct Nested; };

R<R<E>, R<C, int>> rr; // \tcode{E::Nested} and \tcode{C} are friends of \tcode{R<R<E>, R<C, int>>}
\end{codeblock}
\end{example}

Expand Down
18 changes: 12 additions & 6 deletions source/declarations.tex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
block-declaration\br
nodeclspec-function-declaration\br
function-definition\br
friend-type-declaration\br
template-declaration\br
deduction-guide\br
linkage-specification\br
Expand Down Expand Up @@ -133,6 +134,11 @@
the declaration that are \emph{not} nested within scopes nested within
the declaration.

\pnum
If a \grammarterm{name-declaration} matches
the syntactic requirements of \grammarterm{friend-type-declaration},
it is a \grammarterm{friend-type-declaration}.

\pnum
A
\grammarterm{simple-declaration} or
Expand Down Expand Up @@ -1536,13 +1542,13 @@
The target scope of $E$ is the nearest enclosing namespace or block scope.

\pnum
If an \grammarterm{elaborated-type-specifier} appears with
the \keyword{friend} specifier as an entire \grammarterm{member-declaration},
the \grammarterm{member-declaration} shall have one of the following forms:
A \grammarterm{friend-type-specifier}
that is an \grammarterm{elaborated-type-specifier}
shall have one of the following forms:
\begin{ncsimplebnf}
\keyword{friend} class-key \opt{nested-name-specifier} identifier \terminal{;}\br
\keyword{friend} class-key simple-template-id \terminal{;}\br
\keyword{friend} class-key nested-name-specifier \opt{\keyword{template}} simple-template-id \terminal{;}
class-key \opt{nested-name-specifier} identifier\br
class-key simple-template-id\br
class-key nested-name-specifier \opt{\keyword{template}} simple-template-id
\end{ncsimplebnf}
Any unqualified lookup for the \grammarterm{identifier} (in the first case)
does not consider scopes that contain
Expand Down
1 change: 1 addition & 0 deletions source/preprocessor.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,7 @@
\defnxname{cpp_user_defined_literals} & \tcode{200809L} \\ \rowsep
\defnxname{cpp_using_enum} & \tcode{201907L} \\ \rowsep
\defnxname{cpp_variable_templates} & \tcode{201304L} \\ \rowsep
\defnxname{cpp_variadic_friend} & \tcode{202403L} \\ \rowsep
\defnxname{cpp_variadic_templates} & \tcode{200704L} \\ \rowsep
\defnxname{cpp_variadic_using} & \tcode{201611L} \\
\end{LongTable}
Expand Down
13 changes: 8 additions & 5 deletions source/templates.tex
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@
\end{note}

\pnum
The
\grammarterm{declaration}
in a
\grammarterm{template-declaration}
(if any)
The \grammarterm{declaration} in a \grammarterm{template-declaration} (if any)
shall
\begin{itemize}
\item declare or define a function, a class, or a variable, or
Expand All @@ -73,6 +69,8 @@

\item define a member template of a class or class template, or

\item be a \grammarterm{friend-type-declaration}, or

\item be a \grammarterm{deduction-guide}, or

\item be an \grammarterm{alias-declaration}.
Expand Down Expand Up @@ -2742,6 +2740,9 @@
\item In a \grammarterm{using-declaration}\iref{namespace.udecl};
the pattern is a \grammarterm{using-declarator}.

\item In a \grammarterm{friend-type-declaration}\iref{class.mem.general};
the pattern is a \grammarterm{friend-type-specifier}.

\item In a template parameter pack that is a pack expansion\iref{temp.param}:
\begin{itemize}
\item
Expand Down Expand Up @@ -4411,6 +4412,8 @@
\grammarterm{elaborated-type-specifier},
\grammarterm{class-or-decltype}, or
\item
a \grammarterm{simple-type-specifier} of a \grammarterm{friend-type-specifier}, or
\item
a \grammarterm{type-specifier} of a
\begin{itemize}
\item \grammarterm{new-type-id},
Expand Down