Files
TheRock/compiler/amd-llvm/clang/test/C/C23/n2900_n3011.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

67 lines
3.9 KiB
C

// RUN: %clang_cc1 -std=c2x -fsyntax-only -Wpre-c2x-compat -verify=compat %s
// RUN: %clang_cc1 -std=c17 -fsyntax-only -pedantic -Wno-comment -verify=pedantic %s
/* WG14 N2900: yes
* Consistent, Warningless, and Intuitive Initialization with {}
*/
/* WG14 N3011: yes
* Consistent, Warningless, and Intuitive Initialization with {}
*/
void test(void) {
struct S { int x, y; } s = {}; // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
pedantic-warning {{use of an empty initializer is a C23 extension}}
int i = {}; // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
pedantic-warning {{use of an empty initializer is a C23 extension}}
int j = (int){}; // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
pedantic-warning {{use of an empty initializer is a C23 extension}}
// C2x 6.7.10p4 says, in part: An array of unknown size shall not be
// initialized by an empty initializer.
// However, Clang allows zero-sized arrays as an extension in both C and C++,
// and this initialization form will deduce the array extent as zero. Given
// that we support empty initialization of an unbounded array in C++, we also
// support it in C.
int unknown_size[] = {}; // pedantic-warning {{zero size arrays are an extension}} \
pedantic-warning {{use of an empty initializer is a C23 extension}} \
compat-warning {{use of an empty initializer is incompatible with C standards before C23}}
int vla[i] = {}; // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
pedantic-warning {{use of an empty initializer is a C23 extension}}
// C99 6.5.2.5 Compound literals constraint 1: The type name shall specify an
// object type or an array of unknown size, but not a variable length array
// type.
int *compound_literal_vla = (int[i]){}; // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
pedantic-warning {{use of an empty initializer is a C23 extension}}\
compat-error {{compound literal cannot be of variable-length array type}} \
pedantic-error {{compound literal cannot be of variable-length array type}}\
struct T {
int i;
struct S s;
} t1 = { 1, {} }; // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
pedantic-warning {{use of an empty initializer is a C23 extension}}
struct T t2 = {
1, {
2, {} // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
pedantic-warning {{use of an empty initializer is a C23 extension}}
}
};
struct T t3 = {
(int){}, // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
pedantic-warning {{use of an empty initializer is a C23 extension}}
{} // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
pedantic-warning {{use of an empty initializer is a C23 extension}}
};
// Ensure that zero initialization does what you'd expect in a constant expr.
// FIXME: the "not an ICE" warning is incorrect for C2x, but we don't yet
// implement WG14 N3038.
_Static_assert((int){} == 0, "what?"); // compat-warning {{use of an empty initializer is incompatible with C standards before C23}} \
pedantic-warning {{use of an empty initializer is a C23 extension}} \
pedantic-warning {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
}