1 // RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -std=c++11 -verify %s
3 // If an expression of literal class type is used in a context where an integral
4 // constant expression is required, then that class type shall have a single
5 // non-explicit conversion function to an integral or unscoped enumeration type
6 namespace std_example
{
9 constexpr A(int i
) : val(i
) { }
10 constexpr operator int() const { return val
; } // expected-note {{here}}
11 constexpr operator long() const { return 43; } // expected-note {{here}}
15 template<int> struct X
{ };
17 X
<a
> x
; // ok, unique conversion to int
18 int ary
[a
]; // expected-error {{ambiguous conversion from type 'const A' to an integral or unscoped enumeration type}}
24 constexpr operator int() const { return 8; }
26 extern struct Incomplete incomplete
; // expected-note 5{{forward decl}}
28 constexpr Explicit() {}
29 constexpr explicit operator int() const { return 4; } // expected-note 5{{here}}
32 constexpr Ambiguous() {}
33 constexpr operator int() const { return 2; } // expected-note 5{{here}}
34 constexpr operator long() const { return 1; } // expected-note 5{{here}}
37 constexpr int test_ok
= ok
; // ok
38 constexpr int test_explicit(expl
); // ok
39 constexpr int test_ambiguous
= ambig
; // ok
41 static_assert(test_ok
== 8, "");
42 static_assert(test_explicit
== 4, "");
43 static_assert(test_ambiguous
== 2, "");
45 // [expr.new]p6: Every constant-expression in a noptr-new-declarator shall be
46 // an integral constant expression
47 auto new1
= new int[1][ok
];
48 auto new2
= new int[1][incomplete
]; // expected-error {{incomplete}}
49 auto new3
= new int[1][expl
]; // expected-error {{explicit conversion}}
50 auto new4
= new int[1][ambig
]; // expected-error {{ambiguous conversion}}
52 // [dcl.enum]p5: If the underlying type is not fixed [...] the initializing
53 // value [...] shall be an integral constant expression.
56 enum2
= incomplete
, // expected-error {{incomplete}}
57 enum3
= expl
, // expected-error {{explicit conversion}}
58 enum4
= ambig
// expected-error {{ambiguous conversion}}
61 // [dcl.align]p2: When the alignment-specifier is of the form
62 // alignas(assignment-expression), the assignment-expression shall be an
63 // integral constant expression
64 alignas(ok
) int alignas1
;
65 alignas(incomplete
) int alignas2
; // expected-error {{incomplete}}
66 alignas(expl
) int alignas3
; // expected-error {{explicit conversion}}
67 alignas(ambig
) int alignas4
; // expected-error {{ambiguous conversion}}
69 // [dcl.array]p1: If the constant-expression is present, it shall be an integral
70 // constant expression
72 int array2
[incomplete
]; // expected-error {{incomplete}}
73 int array3
[expl
]; // expected-error {{explicit conversion}}
74 int array4
[ambig
]; // expected-error {{ambiguous conversion}}
76 // [class.bit]p1: The constasnt-expression shall be an integral constant
80 int bitfield2
: incomplete
; // expected-error {{incomplete}}
81 int bitfield3
: expl
; // expected-error {{explicit conversion}}
82 int bitfield4
: ambig
; // expected-error {{ambiguous conversion}}