Skip to content

Commit 612d365

Browse files
committed
Add string-to-int bitcast test
1 parent ee8d32d commit 612d365

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

clang/test/AST/Interp/builtin-bit-cast.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,24 @@ template <class To, class From>
3131
constexpr To bit_cast(const From &from) {
3232
static_assert(sizeof(To) == sizeof(From));
3333
return __builtin_bit_cast(To, from); // ref-note 2{{indeterminate value can only initialize}} \
34-
// expected-note 2{{indeterminate value can only initialize}}
34+
// expected-note 2{{indeterminate value can only initialize}} \
35+
// ref-note {{subexpression not valid}}
3536
}
3637

38+
39+
/// Current interpreter does not support this.
40+
/// https://github.com/llvm/llvm-project/issues/63686
41+
constexpr int FromString = bit_cast<int>("abc"); // ref-error {{must be initialized by a constant expression}} \
42+
// ref-note {{in call to}} \
43+
// ref-note {{declared here}}
44+
#if LITTLE_END
45+
static_assert(FromString == 6513249); // ref-error {{is not an integral constant expression}} \
46+
// ref-note {{initializer of 'FromString' is not a constant expression}}
47+
#else
48+
static_assert(FromString == 1633837824); // ref-error {{is not an integral constant expression}} \
49+
// ref-note {{initializer of 'FromString' is not a constant expression}}
50+
#endif
51+
3752
template <class Intermediate, class Init>
3853
constexpr bool round_trip(const Init &init) {
3954
return bit_cast<Init>(bit_cast<Intermediate>(init)) == init;

0 commit comments

Comments
 (0)