Files
TheRock/compiler/amd-llvm/clang/test/SemaCXX/vla-ext-diag.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

41 lines
3.3 KiB
C++

// RUN: %clang_cc1 -verify=gnu -std=gnu++11 %s
// RUN: %clang_cc1 -verify=expected,cxx11 -Wvla -std=gnu++11 %s
// RUN: %clang_cc1 -verify=expected,cxx11 -std=c++11 %s
// RUN: %clang_cc1 -verify=expected,cxx98 -std=c++98 %s
// RUN: %clang_cc1 -verify=expected,off -std=c++11 -Wno-vla-extension-static-assert %s
// gnu-no-diagnostics
// Demonstrate that we do not diagnose use of VLAs by default in GNU mode, but
// we do diagnose them in C++ mode. Also note that we suggest use of
// static_assert, but only in C++11 and later and only if the warning group is
// not disabled.
// C++98 mode does not emit the same notes as C++11 mode because in C++98,
// we're looking for an integer constant expression, whereas in C++11 and later,
// we're looking for a constant expression that is of integer type (these are
// different operations; ICE looks at the syntactic form of the expression, but
// C++11 constant expressions require calculating the expression value).
void func(int n) { // cxx11-note {{declared here}} off-note {{declared here}}
int vla[n]; // expected-warning {{variable length arrays in C++ are a Clang extension}} \
cxx11-note {{function parameter 'n' with unknown value cannot be used in a constant expression}} \
off-note {{function parameter 'n' with unknown value cannot be used in a constant expression}}
}
void old_style_static_assert(int n) { // cxx11-note 5 {{declared here}} off-note 2 {{declared here}}
int array1[n != 12 ? 1 : -1]; // cxx11-warning {{variable length arrays in C++ are a Clang extension; did you mean to use 'static_assert'?}} \
cxx98-warning {{variable length arrays in C++ are a Clang extension}} \
cxx11-note {{function parameter 'n' with unknown value cannot be used in a constant expression}}
int array2[n != 12 ? -1 : 1]; // cxx11-warning {{variable length arrays in C++ are a Clang extension; did you mean to use 'static_assert'?}} \
cxx98-warning {{variable length arrays in C++ are a Clang extension}} \
cxx11-note {{function parameter 'n' with unknown value cannot be used in a constant expression}}
int array3[n != 12 ? 1 : n]; // expected-warning {{variable length arrays in C++ are a Clang extension}} \
cxx11-note {{function parameter 'n' with unknown value cannot be used in a constant expression}} \
off-note {{function parameter 'n' with unknown value cannot be used in a constant expression}}
int array4[(n ? 1 : -1)]; // cxx11-warning {{variable length arrays in C++ are a Clang extension; did you mean to use 'static_assert'?}} \
cxx98-warning {{variable length arrays in C++ are a Clang extension}} \
cxx11-note {{function parameter 'n' with unknown value cannot be used in a constant expression}}
int array5[n ? 1 : 0]; // expected-warning {{variable length arrays in C++ are a Clang extension}} \
cxx11-note {{function parameter 'n' with unknown value cannot be used in a constant expression}} \
off-note {{function parameter 'n' with unknown value cannot be used in a constant expression}}
}