Skip to content

Commit 4d4bf34

Browse files
authored
Merge 2019-07 CWG Motion 8
P1099R5 Using enum Fixes #2987.
2 parents eddf2c5 + 0d35368 commit 4d4bf34

File tree

4 files changed

+85
-8
lines changed

4 files changed

+85
-8
lines changed

source/basic.tex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@
176176
\item it is
177177
a \grammarterm{using-directive}\iref{namespace.udir},
178178
\item it is
179+
a \grammarterm{using-enum-declaration}\iref{enum.udecl},
180+
\item it is
179181
an explicit instantiation declaration\iref{temp.explicit}, or
180182
\item it is
181183
an explicit specialization\iref{temp.expl.spec} whose

source/classes.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@
440440
\opt{attribute-specifier-seq} \opt{decl-specifier-seq} \opt{member-declarator-list} \terminal{;}\br
441441
function-definition\br
442442
using-declaration\br
443+
using-enum-declaration\br
443444
static_assert-declaration\br
444445
template-declaration\br
445446
deduction-guide\br

source/declarations.tex

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
asm-declaration\br
3939
namespace-alias-definition\br
4040
using-declaration\br
41+
using-enum-declaration\br
4142
using-directive\br
4243
static_assert-declaration\br
4344
alias-declaration\br
@@ -1418,6 +1419,11 @@
14181419
class-key \opt{attribute-specifier-seq} \opt{nested-name-specifier} identifier\br
14191420
class-key simple-template-id\br
14201421
class-key nested-name-specifier \opt{\keyword{template}} simple-template-id\br
1422+
elaborated-enum-specifier
1423+
\end{bnf}
1424+
1425+
\begin{bnf}
1426+
\nontermdef{elaborated-enum-specifier}\br
14211427
\keyword{enum} \opt{nested-name-specifier} identifier
14221428
\end{bnf}
14231429

@@ -6584,7 +6590,9 @@
65846590
the type of the \grammarterm{id-expression} \tcode{y} is ``\tcode{const volatile double}''.
65856591
\end{example}
65866592

6587-
\rSec1[dcl.enum]{Enumeration declarations}%
6593+
\rSec1[enum]{Enumerations}%
6594+
6595+
\rSec2[dcl.enum]{Enumeration declarations}%
65886596
\indextext{enumeration}%
65896597
\indextext{\idxcode{\{\}}!enum declaration@\tcode{enum} declaration}%
65906598
\indextext{\idxcode{enum}!type of}
@@ -6904,6 +6912,60 @@
69046912
\end{codeblock}
69056913
\end{example}
69066914

6915+
\rSec2[enum.udecl]{The \tcode{using enum} declaration}%
6916+
\indextext{enumeration!using declaration}%
6917+
6918+
\begin{bnf}
6919+
\nontermdef{using-enum-declaration}\br
6920+
\terminal{using} elaborated-enum-specifier \terminal{;}
6921+
\end{bnf}
6922+
6923+
\pnum
6924+
The \grammarterm{elaborated-enum-specifier}
6925+
shall not name a dependent type
6926+
and the type shall have a reachable \grammarterm{enum-specifier}.
6927+
6928+
\pnum
6929+
A \grammarterm{using-enum-declaration}
6930+
introduces the enumerator names of the named enumeration
6931+
as if by a \grammarterm{using-declaration} for each enumerator.
6932+
6933+
\pnum
6934+
\begin{note}
6935+
A \grammarterm{using-enum-declaration} in class scope
6936+
adds the enumerators of the named enumeration as members to the scope.
6937+
This means they are accessible for member lookup.
6938+
\begin{example}
6939+
\begin{codeblock}
6940+
enum class fruit { orange, apple };
6941+
struct S {
6942+
using enum fruit; // OK, introduces \tcode{orange} and \tcode{apple} into \tcode{S}
6943+
};
6944+
void f() {
6945+
S s;
6946+
s.orange; // OK, names \tcode{fruit::orange}
6947+
S::orange; // OK, names \tcode{fruit::orange}
6948+
}
6949+
\end{codeblock}
6950+
\end{example}
6951+
\end{note}
6952+
6953+
\pnum
6954+
\begin{note}
6955+
Two \grammarterm{using-enum-declaration}s
6956+
that introduce two enumerators of the same name conflict.
6957+
\begin{example}
6958+
\begin{codeblock}
6959+
enum class fruit { orange, apple };
6960+
enum class color { red, orange };
6961+
void f() {
6962+
using enum fruit; // OK
6963+
using enum color; // ill-formed: \tcode{color::orange} and \tcode{fruit::orange} conflict
6964+
}
6965+
\end{codeblock}
6966+
\end{example}
6967+
\end{note}
6968+
69076969
\rSec1[basic.namespace]{Namespaces}%
69086970
\indextext{namespaces|(}
69096971

@@ -7319,7 +7381,7 @@
73197381
\end{codeblock}
73207382
\end{example}
73217383

7322-
\rSec2[namespace.udir]{Using directive}%
7384+
\rSec2[namespace.udir]{Using namespace directive}%
73237385
\indextext{using-directive|(}
73247386

73257387
\begin{bnf}
@@ -7599,8 +7661,20 @@
75997661
\pnum
76007662
In a \grammarterm{using-declaration} used as a
76017663
\grammarterm{member-declaration},
7602-
each \grammarterm{using-declarator}{'s} \grammarterm{nested-name-specifier}
7603-
shall name a base class of the class being defined. If a
7664+
each \grammarterm{using-declarator}
7665+
shall either name an enumerator
7666+
or have a \grammarterm{nested-name-specifier}
7667+
naming a base class of the class being defined.
7668+
\begin{example}
7669+
\begin{codeblock}
7670+
enum class button { up, down };
7671+
struct S {
7672+
using button::up;
7673+
button b = up; // OK
7674+
};
7675+
\end{codeblock}
7676+
\end{example}
7677+
If a
76047678
\grammarterm{using-declarator} names a constructor, its
76057679
\grammarterm{nested-name-specifier} shall name a direct base class of the class
76067680
being defined.
@@ -7667,10 +7741,9 @@
76677741
A \grammarterm{using-declaration} shall not name a namespace.
76687742

76697743
\pnum
7670-
A \grammarterm{using-declaration} shall not name a scoped enumerator.
7671-
7672-
\pnum
7673-
A \grammarterm{using-declaration} that names a class member shall be a
7744+
A \grammarterm{using-declaration} that names a class member
7745+
other than an enumerator
7746+
shall be a
76747747
\grammarterm{member-declaration}.
76757748
\begin{example}
76767749
\begin{codeblock}

source/preprocessor.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,7 @@
17221722
\defnxname{cpp_unicode_characters} & \tcode{200704L} \\ \rowsep
17231723
\defnxname{cpp_unicode_literals} & \tcode{200710L} \\ \rowsep
17241724
\defnxname{cpp_user_defined_literals} & \tcode{200809L} \\ \rowsep
1725+
\defnxname{cpp_using_enum} & \tcode{201907L} \\ \rowsep
17251726
\defnxname{cpp_variable_templates} & \tcode{201304L} \\ \rowsep
17261727
\defnxname{cpp_variadic_templates} & \tcode{200704L} \\ \rowsep
17271728
\defnxname{cpp_variadic_using} & \tcode{201611L} \\ \rowsep

0 commit comments

Comments
 (0)