|
5584 | 5584 | and as alignments~(\ref{dcl.align}).
|
5585 | 5585 | \end{note}
|
5586 | 5586 |
|
| 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 | + |
5587 | 5608 | \pnum
|
5588 | 5609 | A \defnx{converted constant expression}{expression!converted constant}
|
5589 | 5610 | of type \tcode{T} is an
|
|
5668 | 5689 | }
|
5669 | 5690 | \end{codeblock}
|
5670 | 5691 | 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}% |
5693 | 5693 | \indextext{expression|)}
|
0 commit comments