Files
TheRock/compiler/amd-llvm/clang/test/SemaCXX/warn-bitfield-enum-conversion.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

60 lines
2.5 KiB
C++

// RUN: %clang_cc1 -std=c++11 -triple x86_64-windows-msvc -verify %s -Wbitfield-enum-conversion
// RUN: %clang_cc1 -std=c++11 -triple x86_64-linux -verify %s -Wbitfield-enum-conversion
enum TwoBits { Hi1 = 3 } two_bits;
enum TwoBitsSigned { Lo2 = -2, Hi2 = 1 } two_bits_signed;
enum ThreeBits { Hi3 = 7 } three_bits;
enum ThreeBitsSigned { Lo4 = -4, Hi4 = 3 } three_bits_signed;
enum TwoBitsFixed : unsigned { Hi5 = 3 } two_bits_fixed;
struct Foo {
unsigned two_bits : 2; // expected-note 2 {{widen this field to 3 bits}} expected-note 2 {{type signed}}
int two_bits_signed : 2; // expected-note 2 {{widen this field to 3 bits}} expected-note 1 {{type unsigned}}
unsigned three_bits : 3; // expected-note 2 {{type signed}}
int three_bits_signed : 3; // expected-note 1 {{type unsigned}}
#ifdef _WIN32
// expected-note@+2 {{type unsigned}}
#endif
ThreeBits three_bits_enum : 3;
ThreeBits four_bits_enum : 4;
};
void f() {
Foo f;
f.two_bits = two_bits;
f.two_bits = two_bits_signed; // expected-warning {{negative enumerators}}
f.two_bits = three_bits; // expected-warning {{not wide enough}}
f.two_bits = three_bits_signed; // expected-warning {{negative enumerators}} expected-warning {{not wide enough}}
f.two_bits = two_bits_fixed;
f.two_bits_signed = two_bits; // expected-warning {{needs an extra bit}}
f.two_bits_signed = two_bits_signed;
f.two_bits_signed = three_bits; // expected-warning {{not wide enough}}
f.two_bits_signed = three_bits_signed; // expected-warning {{not wide enough}}
f.three_bits = two_bits;
f.three_bits = two_bits_signed; // expected-warning {{negative enumerators}}
f.three_bits = three_bits;
f.three_bits = three_bits_signed; // expected-warning {{negative enumerators}}
f.three_bits_signed = two_bits;
f.three_bits_signed = two_bits_signed;
f.three_bits_signed = three_bits; // expected-warning {{needs an extra bit}}
f.three_bits_signed = three_bits_signed;
#ifdef _WIN32
// Enums on Windows are always implicitly 'int', which is signed, so you need
// an extra bit to store values that set the MSB. This is not true on SysV
// platforms like Linux.
// expected-warning@+2 {{needs an extra bit}}
#endif
f.three_bits_enum = three_bits;
f.four_bits_enum = three_bits;
// Explicit casts suppress the warning.
f.two_bits = (unsigned)three_bits_signed;
f.two_bits = static_cast<unsigned>(three_bits_signed);
}