Skip to content

P1099R5 Using enum #3047

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 2 commits into from
Aug 2, 2019
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: 2 additions & 0 deletions source/basic.tex
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@
\item it is
a \grammarterm{using-directive}\iref{namespace.udir},
\item it is
a \grammarterm{using-enum-declaration}\iref{enum.udecl},
\item it is
an explicit instantiation declaration\iref{temp.explicit}, or
\item it is
an explicit specialization\iref{temp.expl.spec} whose
Expand Down
1 change: 1 addition & 0 deletions source/classes.tex
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@
\opt{attribute-specifier-seq} \opt{decl-specifier-seq} \opt{member-declarator-list} \terminal{;}\br
function-definition\br
using-declaration\br
using-enum-declaration\br
static_assert-declaration\br
template-declaration\br
deduction-guide\br
Expand Down
89 changes: 81 additions & 8 deletions source/declarations.tex
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
asm-declaration\br
namespace-alias-definition\br
using-declaration\br
using-enum-declaration\br
using-directive\br
static_assert-declaration\br
alias-declaration\br
Expand Down Expand Up @@ -1418,6 +1419,11 @@
class-key \opt{attribute-specifier-seq} \opt{nested-name-specifier} identifier\br
class-key simple-template-id\br
class-key nested-name-specifier \opt{\keyword{template}} simple-template-id\br
elaborated-enum-specifier
\end{bnf}

\begin{bnf}
\nontermdef{elaborated-enum-specifier}\br
\keyword{enum} \opt{nested-name-specifier} identifier
\end{bnf}

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

\rSec1[dcl.enum]{Enumeration declarations}%
\rSec1[enum]{Enumerations}%

\rSec2[dcl.enum]{Enumeration declarations}%
\indextext{enumeration}%
\indextext{\idxcode{\{\}}!enum declaration@\tcode{enum} declaration}%
\indextext{\idxcode{enum}!type of}
Expand Down Expand Up @@ -6904,6 +6912,60 @@
\end{codeblock}
\end{example}

\rSec2[enum.udecl]{The \tcode{using enum} declaration}%
\indextext{enumeration!using declaration}%

\begin{bnf}
\nontermdef{using-enum-declaration}\br
\terminal{using} elaborated-enum-specifier \terminal{;}
\end{bnf}

\pnum
The \grammarterm{elaborated-enum-specifier}
shall not name a dependent type
and the type shall have a reachable \grammarterm{enum-specifier}.

\pnum
A \grammarterm{using-enum-declaration}
introduces the enumerator names of the named enumeration
as if by a \grammarterm{using-declaration} for each enumerator.

\pnum
\begin{note}
A \grammarterm{using-enum-declaration} in class scope
adds the enumerators of the named enumeration as members to the scope.
This means they are accessible for member lookup.
\begin{example}
\begin{codeblock}
enum class fruit { orange, apple };
struct S {
using enum fruit; // OK, introduces \tcode{orange} and \tcode{apple} into \tcode{S}
};
void f() {
S s;
s.orange; // OK, names \tcode{fruit::orange}
S::orange; // OK, names \tcode{fruit::orange}
}
\end{codeblock}
\end{example}
\end{note}

\pnum
\begin{note}
Two \grammarterm{using-enum-declaration}s
that introduce two enumerators of the same name conflict.
\begin{example}
\begin{codeblock}
enum class fruit { orange, apple };
enum class color { red, orange };
void f() {
using enum fruit; // OK
using enum color; // ill-formed: \tcode{color::orange} and \tcode{fruit::orange} conflict
}
\end{codeblock}
\end{example}
\end{note}

\rSec1[basic.namespace]{Namespaces}%
\indextext{namespaces|(}

Expand Down Expand Up @@ -7319,7 +7381,7 @@
\end{codeblock}
\end{example}

\rSec2[namespace.udir]{Using directive}%
\rSec2[namespace.udir]{Using namespace directive}%
\indextext{using-directive|(}

\begin{bnf}
Expand Down Expand Up @@ -7599,8 +7661,20 @@
\pnum
In a \grammarterm{using-declaration} used as a
\grammarterm{member-declaration},
each \grammarterm{using-declarator}{'s} \grammarterm{nested-name-specifier}
shall name a base class of the class being defined. If a
each \grammarterm{using-declarator}
shall either name an enumerator
or have a \grammarterm{nested-name-specifier}
naming a base class of the class being defined.
\begin{example}
\begin{codeblock}
enum class button { up, down };
struct S {
using button::up;
button b = up; // OK
};
\end{codeblock}
\end{example}
If a
\grammarterm{using-declarator} names a constructor, its
\grammarterm{nested-name-specifier} shall name a direct base class of the class
being defined.
Expand Down Expand Up @@ -7667,10 +7741,9 @@
A \grammarterm{using-declaration} shall not name a namespace.

\pnum
A \grammarterm{using-declaration} shall not name a scoped enumerator.

\pnum
A \grammarterm{using-declaration} that names a class member shall be a
A \grammarterm{using-declaration} that names a class member
other than an enumerator
shall be a
\grammarterm{member-declaration}.
\begin{example}
\begin{codeblock}
Expand Down
1 change: 1 addition & 0 deletions source/preprocessor.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,7 @@
\defnxname{cpp_unicode_characters} & \tcode{200704L} \\ \rowsep
\defnxname{cpp_unicode_literals} & \tcode{200710L} \\ \rowsep
\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_templates} & \tcode{200704L} \\ \rowsep
\defnxname{cpp_variadic_using} & \tcode{201611L} \\ \rowsep
Expand Down