Skip to content

Commit 19c6314

Browse files
cpplearnerzygoloid
authored andcommitted
[expr.const] Move p7 next to p3.
1 parent bbca26c commit 19c6314

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

source/expressions.tex

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5584,6 +5584,27 @@
55845584
and as alignments~(\ref{dcl.align}).
55855585
\end{note}
55865586

5587+
\pnum
5588+
If an expression of literal class type is used in a context where an
5589+
integral constant expression is required, then that expression is
5590+
contextually implicitly converted (Clause~\ref{conv}) to an integral or unscoped
5591+
enumeration type
5592+
and the selected conversion function shall be \tcode{constexpr}. \begin{example}
5593+
\begin{codeblock}
5594+
struct A {
5595+
constexpr A(int i) : val(i) { }
5596+
constexpr operator int() const { return val; }
5597+
constexpr operator long() const { return 42; }
5598+
private:
5599+
int val;
5600+
};
5601+
template<int> struct X { };
5602+
constexpr A a = alignof(int);
5603+
alignas(a) int n; // error: ambiguous conversion
5604+
struct B { int n : a; }; // error: ambiguous conversion
5605+
\end{codeblock}
5606+
\end{example}
5607+
55875608
\pnum
55885609
A \defnx{converted constant expression}{expression!converted constant}
55895610
of type \tcode{T} is an
@@ -5668,26 +5689,5 @@
56685689
}
56695690
\end{codeblock}
56705691
It is unspecified whether the value of \tcode{f()} will be \tcode{true} or \tcode{false}.
5671-
\end{example} \end{note}
5672-
5673-
\pnum
5674-
If an expression of literal class type is used in a context where an
5675-
integral constant expression is required, then that expression is
5676-
contextually implicitly converted (Clause~\ref{conv}) to an integral or unscoped
5677-
enumeration type
5678-
and the selected conversion function shall be \tcode{constexpr}. \begin{example}
5679-
\begin{codeblock}
5680-
struct A {
5681-
constexpr A(int i) : val(i) { }
5682-
constexpr operator int() const { return val; }
5683-
constexpr operator long() const { return 42; }
5684-
private:
5685-
int val;
5686-
};
5687-
template<int> struct X { };
5688-
constexpr A a = alignof(int);
5689-
alignas(a) int n; // error: ambiguous conversion
5690-
struct B { int n : a; }; // error: ambiguous conversion
5691-
\end{codeblock}
5692-
\end{example}%
5692+
\end{example} \end{note}%
56935693
\indextext{expression|)}

0 commit comments

Comments
 (0)