Skip to content

Commit 34eb474

Browse files
Dawn Perchikzygoloid
authored andcommitted
P0138R2 Construction Rules for enum class Values
1 parent 2c492b8 commit 34eb474

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

source/declarators.tex

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3738,6 +3738,34 @@
37383738
\end{codeblock}
37393739
\exitexample
37403740

3741+
\item Otherwise, if \tcode{T} is an enumeration
3742+
with a fixed underlying type~(\ref{dcl.enum}),
3743+
the \grammarterm{initializer-list} has a single element \tcode{v}, and
3744+
the initialization is direct-list-initialization,
3745+
the object is initialized with the value \tcode{T(v)}~(\ref{expr.type.conv});
3746+
if a narrowing conversion is required to convert \tcode{v}
3747+
to the underlying type of \tcode{T}, the program is ill-formed.
3748+
3749+
\enterexample
3750+
\begin{codeblock}
3751+
enum byte : unsigned char { };
3752+
byte b { 42 }; // OK
3753+
byte c = { 42 }; // error
3754+
byte d = byte{ 42 }; // OK; same value as \tcode{b}
3755+
byte e { -1 }; // error
3756+
3757+
struct A { byte b; };
3758+
A a1 = { { 42 } }; // error
3759+
A a2 = { byte{ 42 } }; // OK
3760+
3761+
void f(byte);
3762+
f({ 42 }); // error
3763+
3764+
enum class Handle : uint32_t { Invalid = 0 };
3765+
Handle h { 42 }; // OK
3766+
\end{codeblock}
3767+
\exitexample
3768+
37413769
\item Otherwise, if the initializer list has no elements, the object is
37423770
value-initialized.
37433771

0 commit comments

Comments
 (0)