Files
TheRock/compiler/amd-llvm/clang/test/SemaCXX/cxx1z-init-statement.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

108 lines
2.3 KiB
C++

// RUN: %clang_cc1 -std=c++1z -Wno-unused-value -verify %s
// RUN: %clang_cc1 -std=c++17 -Wno-unused-value -verify %s
void testIf() {
int x = 0;
if (x; x) ++x;
if (int t = 0; t) ++t; else --t;
if (int x, y = 0; y) // expected-note 2 {{previous definition is here}}
int x = 0; // expected-error {{redefinition of 'x'}}
else
int x = 0; // expected-error {{redefinition of 'x'}}
if (x; int a = 0) ++a;
if (x, +x; int a = 0) // expected-note 2 {{previous definition is here}}
int a = 0; // expected-error {{redefinition of 'a'}}
else
int a = 0; // expected-error {{redefinition of 'a'}}
if (int b = 0; b)
;
b = 2; // expected-error {{use of undeclared identifier}}
}
void testSwitch() {
int x = 0;
switch (x; x) {
case 1:
++x;
}
switch (int x, y = 0; y) {
case 1:
++x;
default:
++y;
}
switch (int x, y = 0; y) { // expected-note 2 {{previous definition is here}}
case 0:
int x = 0; // expected-error {{redefinition of 'x'}}
case 1:
int y = 0; // expected-error {{redefinition of 'y'}}
};
switch (x; int a = 0) {
case 0:
++a;
}
switch (x, +x; int a = 0) { // expected-note {{previous definition is here}}
case 0:
int a = 0; // expected-error {{redefinition of 'a'}} // expected-note {{previous definition is here}}
case 1:
int a = 0; // expected-error {{redefinition of 'a'}}
}
switch (int b = 0; b) {
case 0:
break;
}
b = 2; // expected-error {{use of undeclared identifier}}
}
constexpr bool constexpr_if_init(int n) {
if (int a = n; ++a > 0)
return true;
else
return false;
}
constexpr int constexpr_switch_init(int n) {
switch (int p = n + 2; p) {
case 0:
return 0;
case 1:
return 1;
default:
return -1;
}
}
void test_constexpr_init_stmt() {
constexpr bool a = constexpr_if_init(-2);
static_assert(!a, "");
static_assert(constexpr_if_init(1), "");
constexpr int b = constexpr_switch_init(-1);
static_assert(b == 1, "");
static_assert(constexpr_switch_init(-2) == 0, "");
static_assert(constexpr_switch_init(-5) == -1, "");
}
int test_lambda_init() {
if (int x = []() {int x = 42; return x; }(); x) {
};
switch (int y = []() {int y = 42; return y; }(); y) {
case 42:
return 1;
}
for (int x = [] { int x = 0; return x; }();;)
;
return 0;
}