Files
TheRock/compiler/amd-llvm/clang/test/Sema/warn-outof-range-assign-enum.c
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

73 lines
2.7 KiB
C

// RUN: %clang_cc1 -fsyntax-only -verify -Wassign-enum %s
typedef enum CCTestEnum
{
One,
Two=4,
Three
} CCTestEnum;
CCTestEnum test = 50; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
CCTestEnum test1 = -50; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
// Explicit cast should silence the warning.
static const CCTestEnum SilenceWithCast1 = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
static const CCTestEnum SilenceWithCast2 = (CCTestEnum) 51; // no-warning
static const CCTestEnum SilenceWithCast3 = (const CCTestEnum) 51; // no-warning
static const CCTestEnum SilenceWithCast4 = (const volatile CCTestEnum) 51; // no-warning
void SilenceWithCastLocalVar(void) {
CCTestEnum SilenceWithCast1 = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
CCTestEnum SilenceWithCast2 = (CCTestEnum) 51; // no-warning
CCTestEnum SilenceWithCast3 = (const CCTestEnum) 51; // no-warning
CCTestEnum SilenceWithCast4 = (const volatile CCTestEnum) 51; // no-warning
const CCTestEnum SilenceWithCast1c = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
const CCTestEnum SilenceWithCast2c = (CCTestEnum) 51; // no-warning
const CCTestEnum SilenceWithCast3c = (const CCTestEnum) 51; // no-warning
const CCTestEnum SilenceWithCast4c = (const volatile CCTestEnum) 51; // no-warning
}
CCTestEnum foo(CCTestEnum r) {
return 20; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
}
enum Test2 { K_zero, K_one };
enum Test2 test2(enum Test2 *t) {
*t = 20; // expected-warning {{integer constant not in range of enumerated type 'enum Test2'}}
return 10; // expected-warning {{integer constant not in range of enumerated type 'enum Test2'}}
}
// PR15069
typedef enum
{
a = 0
} T;
void f(void)
{
T x = a;
x += 1; // expected-warning {{integer constant not in range of enumerated type}}
}
typedef enum OutOfOrderTestEnum {
OO1 = 100,
OO2 = 50,
OO3 = 75,
OO4 = 9,
OO5 = 99
} OutOfOrderTestEnum;
OutOfOrderTestEnum t1 = 75;
OutOfOrderTestEnum t2 = 9;
OutOfOrderTestEnum t3 = 76; // expected-warning {{integer constant not in range of enumerated type 'OutOfOrderTestEnum'}}
int main(void) {
CCTestEnum test = 1; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
test = 600; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
foo(2); // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
foo(-1); // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
foo(4);
foo(Two+1);
}