Files
TheRock/compiler/amd-llvm/clang/test/SemaCXX/builtin-bit-cast.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

59 lines
1.8 KiB
C++

// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -triple x86_64-apple-macosx10.14.0 %s
// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -triple x86_64-apple-macosx10.14.0 %s -fno-signed-char
#if !__has_builtin(__builtin_bit_cast)
#error
#endif
template <class T, T v>
T instantiate() {
return __builtin_bit_cast(T, v);
}
int x = instantiate<int, 32>();
struct secret_ctor {
char member;
private: secret_ctor() = default;
};
void test1() {
secret_ctor c = __builtin_bit_cast(secret_ctor, (char)0);
}
void test2() {
constexpr int i = 0;
// expected-error@+1{{size of '__builtin_bit_cast' source type 'const int' does not match destination type 'char' (4 vs 1 bytes)}}
constexpr char c = __builtin_bit_cast(char, i);
}
struct not_trivially_copyable {
virtual void foo() {}
};
// expected-error@+1{{'__builtin_bit_cast' source type must be trivially copyable}}
constexpr unsigned long ul = __builtin_bit_cast(unsigned long, not_trivially_copyable{});
// expected-error@+1 {{'__builtin_bit_cast' destination type must be trivially copyable}}
constexpr long us = __builtin_bit_cast(unsigned long &, 0L);
namespace PR42936 {
template <class T> struct S { int m; };
extern S<int> extern_decl;
int x = __builtin_bit_cast(int, extern_decl);
S<char> y = __builtin_bit_cast(S<char>, 0);
}
template <class To, class From>
// expected-note@+1{{possible target for call}}
constexpr To bit_cast(const From &from) {
return __builtin_bit_cast(To, bit_cast);
// expected-error@-1{{reference to overloaded function could not be resolved; did you mean to call it?}}
} // expected-note {{control reached end of constexpr function}}
constexpr __int128_t foo = bit_cast<__int128_t>((long double)0);
// expected-error@-1{{constexpr variable 'foo' must be initialized by a constant expression}}
// expected-note@-2{{in call to 'bit_cast<__int128, long double>((long double)0)'}}