Skip to content

Commit 770b3f4

Browse files
authored
Merge 2024-03 CWG Motion 10
P2893R3 Variadic friends
2 parents faa572d + a922aec commit 770b3f4

File tree

4 files changed

+62
-23
lines changed

4 files changed

+62
-23
lines changed

source/classes.tex

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@
462462
\nontermdef{member-declaration}\br
463463
\opt{attribute-specifier-seq} \opt{decl-specifier-seq} \opt{member-declarator-list} \terminal{;}\br
464464
function-definition\br
465+
friend-type-declaration\br
465466
using-declaration\br
466467
using-enum-declaration\br
467468
static_assert-declaration\br
@@ -504,6 +505,24 @@
504505
\terminal{=} \terminal{0}
505506
\end{bnf}
506507

508+
\begin{bnf}
509+
\nontermdef{friend-type-declaration}\br
510+
\keyword{friend} friend-type-specifier-list \terminal{;}
511+
\end{bnf}
512+
513+
\begin{bnf}
514+
\nontermdef{friend-type-specifier-list}\br
515+
friend-type-specifier \opt{\terminal{...}}\br
516+
friend-type-specifier-list \terminal{,} friend-type-specifier \opt{\terminal{...}}
517+
\end{bnf}
518+
519+
\begin{bnf}
520+
\nontermdef{friend-type-specifier}\br
521+
simple-type-specifier\br
522+
elaborated-type-specifier\br
523+
typename-specifier
524+
\end{bnf}
525+
507526
\pnum
508527
In the absence of a \grammarterm{virt-specifier-seq},
509528
the token sequence \tcode{= 0} is treated as a \grammarterm{pure-specifier}
@@ -623,6 +642,11 @@
623642
or if $P$ is in a complete-class context of \tcode{C}.
624643
Otherwise, \tcode{C} is incomplete at $P$.
625644

645+
\pnum
646+
If a \grammarterm{member-declaration} matches
647+
the syntactic requirements of \grammarterm{friend-type-declaration},
648+
it is a \grammarterm{friend-type-declaration}.
649+
626650
\pnum
627651
In a \grammarterm{member-declarator},
628652
an \tcode{=} immediately following the \grammarterm{declarator}
@@ -4787,27 +4811,22 @@
47874811

47884812
\pnum
47894813
A friend declaration that does not declare a function
4790-
shall have one of the following forms:
4791-
4792-
\begin{ncsimplebnf}
4793-
\keyword{friend} elaborated-type-specifier \terminal{;}\br
4794-
\keyword{friend} simple-type-specifier \terminal{;}\br
4795-
\keyword{friend} typename-specifier \terminal{;}
4796-
\end{ncsimplebnf}
4814+
shall be a \grammarterm{friend-type-declaration}.
47974815

47984816
\begin{note}
47994817
A friend declaration can be the
48004818
\grammarterm{declaration} in
48014819
a \grammarterm{template-declaration}\iref{temp.pre,temp.friend}.
48024820
\end{note}
4803-
If the
4804-
type specifier in a friend declaration designates a (possibly
4821+
If a \grammarterm{friend-type-specifier} in a friend declaration
4822+
designates a (possibly
48054823
cv-qualified) class type, that class is declared as a friend; otherwise, the
4806-
friend declaration is ignored.
4824+
\grammarterm{friend-type-specifier} is ignored.
48074825
\begin{example}
48084826
\begin{codeblock}
48094827
class C;
48104828
typedef C Ct;
4829+
class E;
48114830

48124831
class X1 {
48134832
friend C; // OK, \tcode{class C} is a friend
@@ -4819,12 +4838,22 @@
48194838
friend class D; // OK, elaborated-type-specifier declares new class
48204839
};
48214840

4822-
template <typename T> class R {
4823-
friend T;
4841+
template <typename ... Ts> class R {
4842+
friend Ts...;
4843+
};
4844+
4845+
template <class... Ts, class... Us>
4846+
class R<R<Ts...>, R<Us...>> {
4847+
friend Ts::Nested..., Us...;
48244848
};
48254849

48264850
R<C> rc; // \tcode{class C} is a friend of \tcode{R<C>}
4851+
R<C, E> rce; // classes \tcode{C} and \tcode{E} are friends of \tcode{R<C, E>}
48274852
R<int> Ri; // OK, \tcode{"friend int;"} is ignored
4853+
4854+
struct E { struct Nested; };
4855+
4856+
R<R<E>, R<C, int>> rr; // \tcode{E::Nested} and \tcode{C} are friends of \tcode{R<R<E>, R<C, int>>}
48284857
\end{codeblock}
48294858
\end{example}
48304859

source/declarations.tex

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
block-declaration\br
2929
nodeclspec-function-declaration\br
3030
function-definition\br
31+
friend-type-declaration\br
3132
template-declaration\br
3233
deduction-guide\br
3334
linkage-specification\br
@@ -133,6 +134,11 @@
133134
the declaration that are \emph{not} nested within scopes nested within
134135
the declaration.
135136

137+
\pnum
138+
If a \grammarterm{name-declaration} matches
139+
the syntactic requirements of \grammarterm{friend-type-declaration},
140+
it is a \grammarterm{friend-type-declaration}.
141+
136142
\pnum
137143
A
138144
\grammarterm{simple-declaration} or
@@ -1536,13 +1542,13 @@
15361542
The target scope of $E$ is the nearest enclosing namespace or block scope.
15371543

15381544
\pnum
1539-
If an \grammarterm{elaborated-type-specifier} appears with
1540-
the \keyword{friend} specifier as an entire \grammarterm{member-declaration},
1541-
the \grammarterm{member-declaration} shall have one of the following forms:
1545+
A \grammarterm{friend-type-specifier}
1546+
that is an \grammarterm{elaborated-type-specifier}
1547+
shall have one of the following forms:
15421548
\begin{ncsimplebnf}
1543-
\keyword{friend} class-key \opt{nested-name-specifier} identifier \terminal{;}\br
1544-
\keyword{friend} class-key simple-template-id \terminal{;}\br
1545-
\keyword{friend} class-key nested-name-specifier \opt{\keyword{template}} simple-template-id \terminal{;}
1549+
class-key \opt{nested-name-specifier} identifier\br
1550+
class-key simple-template-id\br
1551+
class-key nested-name-specifier \opt{\keyword{template}} simple-template-id
15461552
\end{ncsimplebnf}
15471553
Any unqualified lookup for the \grammarterm{identifier} (in the first case)
15481554
does not consider scopes that contain

source/preprocessor.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,7 @@
19031903
\defnxname{cpp_user_defined_literals} & \tcode{200809L} \\ \rowsep
19041904
\defnxname{cpp_using_enum} & \tcode{201907L} \\ \rowsep
19051905
\defnxname{cpp_variable_templates} & \tcode{201304L} \\ \rowsep
1906+
\defnxname{cpp_variadic_friend} & \tcode{202403L} \\ \rowsep
19061907
\defnxname{cpp_variadic_templates} & \tcode{200704L} \\ \rowsep
19071908
\defnxname{cpp_variadic_using} & \tcode{201611L} \\
19081909
\end{LongTable}

source/templates.tex

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@
5959
\end{note}
6060

6161
\pnum
62-
The
63-
\grammarterm{declaration}
64-
in a
65-
\grammarterm{template-declaration}
66-
(if any)
62+
The \grammarterm{declaration} in a \grammarterm{template-declaration} (if any)
6763
shall
6864
\begin{itemize}
6965
\item declare or define a function, a class, or a variable, or
@@ -73,6 +69,8 @@
7369

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

72+
\item be a \grammarterm{friend-type-declaration}, or
73+
7674
\item be a \grammarterm{deduction-guide}, or
7775

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

2743+
\item In a \grammarterm{friend-type-declaration}\iref{class.mem.general};
2744+
the pattern is a \grammarterm{friend-type-specifier}.
2745+
27452746
\item In a template parameter pack that is a pack expansion\iref{temp.param}:
27462747
\begin{itemize}
27472748
\item
@@ -4411,6 +4412,8 @@
44114412
\grammarterm{elaborated-type-specifier},
44124413
\grammarterm{class-or-decltype}, or
44134414
\item
4415+
a \grammarterm{simple-type-specifier} of a \grammarterm{friend-type-specifier}, or
4416+
\item
44144417
a \grammarterm{type-specifier} of a
44154418
\begin{itemize}
44164419
\item \grammarterm{new-type-id},

0 commit comments

Comments
 (0)