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
149 lines
5.5 KiB
C
149 lines
5.5 KiB
C
// RUN: %clang_cc1 -std=c2x -verify -pedantic -Wno-comments %s
|
|
// RUN: %clang_cc1 -std=c2x -verify -pedantic -Wno-comments %s -fexperimental-new-constant-interpreter
|
|
|
|
void test_basic_types(void) {
|
|
auto undefined; // expected-error {{declaration of variable 'undefined' with deduced type 'auto' requires an initializer}}
|
|
auto auto_int = 4;
|
|
auto auto_long = 4UL;
|
|
auto int auto_int_ts = 12;
|
|
signed auto a = 1L;
|
|
|
|
_Static_assert(_Generic(auto_int, int : 1));
|
|
_Static_assert(_Generic(auto_long, unsigned long : 1));
|
|
}
|
|
|
|
void test_complex_types(void) {
|
|
_Complex auto i = 12.0; // expected-warning {{plain '_Complex' requires a type specifier; assuming '_Complex double'}}
|
|
}
|
|
|
|
void test_gnu_extensions(void) {
|
|
auto t = ({ // expected-warning {{use of GNU statement expression extension}}
|
|
auto b = 12;
|
|
b;
|
|
});
|
|
_Static_assert(_Generic(t, int : 1));
|
|
}
|
|
|
|
void test_sizeof_typeof(void) {
|
|
auto auto_size = sizeof(auto); // expected-error {{expected expression}}
|
|
typeof(auto) tpof = 4; // expected-error {{expected expression}}
|
|
}
|
|
|
|
void test_casts(void) {
|
|
auto int_cast = (int)(4 + 3);
|
|
auto double_cast = (double)(1 / 3);
|
|
auto long_cast = (long)(4UL + 3UL);
|
|
auto auto_cast = (auto)(4 + 3); // expected-error {{expected expression}}
|
|
|
|
_Static_assert(_Generic(int_cast, int : 1));
|
|
_Static_assert(_Generic(double_cast, double : 1));
|
|
_Static_assert(_Generic(long_cast, long : 1));
|
|
}
|
|
|
|
void test_compound_literral(void) {
|
|
auto int_cl = (int){13};
|
|
auto double_cl = (double){2.5};
|
|
auto array[] = { 1, 2, 3 }; // expected-error {{cannot use 'auto' with array in C}}
|
|
|
|
auto auto_cl = (auto){13}; // expected-error {{expected expression}}
|
|
|
|
_Static_assert(_Generic(int_cl, int : 1));
|
|
_Static_assert(_Generic(double_cl, double : 1));
|
|
}
|
|
|
|
void test_array_pointers(void) {
|
|
double array[3] = { 0 };
|
|
auto a = array;
|
|
auto b = &array;
|
|
|
|
_Static_assert(_Generic(array, double * : 1));
|
|
_Static_assert(_Generic(a, double * : 1));
|
|
_Static_assert(_Generic(b, double (*)[3] : 1));
|
|
}
|
|
|
|
void test_typeof() {
|
|
int typeof_target();
|
|
auto result = (typeof(typeof_target())){12};
|
|
|
|
_Static_assert(_Generic(result, int : 1));
|
|
}
|
|
|
|
void test_qualifiers(const int y) {
|
|
const auto a = 12;
|
|
auto b = y;
|
|
static auto c = 1UL;
|
|
int* pa = &a; // expected-warning {{initializing 'int *' with an expression of type 'const int *' discards qualifiers}}
|
|
const int* pb = &b;
|
|
int* pc = &c; // expected-error {{incompatible pointer types initializing 'int *' with an expression of type 'unsigned long *'}}
|
|
|
|
_Static_assert(_Generic(a, int : 1));
|
|
_Static_assert(_Generic(b, int : 1));
|
|
_Static_assert(_Generic(c, unsigned long : 1));
|
|
_Static_assert(_Generic(pa, int * : 1));
|
|
_Static_assert(_Generic(pb, const int * : 1));
|
|
_Static_assert(_Generic(pc, int * : 1));
|
|
}
|
|
|
|
void test_parens(void) {
|
|
auto str = "this is a string";
|
|
auto (str2) = "this is a string";
|
|
auto (((str3))) = "this is a string";
|
|
auto ((((x)))) = 12;
|
|
|
|
_Static_assert(_Generic(str, char * : 1));
|
|
_Static_assert(_Generic(str2, char * : 1));
|
|
_Static_assert(_Generic(str3, char * : 1));
|
|
_Static_assert(_Generic(x, int : 1));
|
|
}
|
|
|
|
void test_pointers(void) {
|
|
auto a = 12;
|
|
auto *ptr = &a; // expected-warning {{type inference of a declaration other than a plain identifier with optional trailing attributes is a Clang extension}}
|
|
auto *str = "this is a string"; // expected-warning {{type inference of a declaration other than a plain identifier with optional trailing attributes is a Clang extension}}
|
|
const auto *str2 = "this is a string"; // expected-warning {{type inference of a declaration other than a plain identifier with optional trailing attributes is a Clang extension}}
|
|
auto *b = &a; // expected-warning {{type inference of a declaration other than a plain identifier with optional trailing attributes is a Clang extension}}
|
|
*b = &a; // expected-error {{incompatible pointer to integer conversion assigning to 'int' from 'int *'; remove &}}
|
|
auto nptr = nullptr;
|
|
|
|
_Static_assert(_Generic(a, int : 1));
|
|
_Static_assert(_Generic(ptr, int * : 1));
|
|
_Static_assert(_Generic(str, char * : 1));
|
|
_Static_assert(_Generic(str2, const char * : 1));
|
|
_Static_assert(_Generic(b, int * : 1));
|
|
_Static_assert(_Generic(nptr, typeof(nullptr) : 1));
|
|
}
|
|
|
|
void test_prototypes(void) {
|
|
extern void foo(int a, int array[({ auto x = 12; x;})]); // expected-warning {{use of GNU statement expression extension}}
|
|
}
|
|
|
|
void test_scopes(void) {
|
|
double a = 7;
|
|
double b = 9;
|
|
{
|
|
auto a = a * a; // expected-error {{variable 'a' declared with deduced type 'auto' cannot appear in its own initializer}} \
|
|
expected-error {{variable 'a' declared with deduced type 'auto' cannot appear in its own initializer}}
|
|
}
|
|
{
|
|
auto b = a * a;
|
|
auto a = b;
|
|
|
|
_Static_assert(_Generic(b, double : 1));
|
|
_Static_assert(_Generic(a, double : 1));
|
|
}
|
|
}
|
|
|
|
[[clang::overloadable]] auto test(auto x) { // expected-error {{'auto' not allowed in function prototype}} \
|
|
expected-error {{'auto' not allowed in function return type}}
|
|
return x;
|
|
}
|
|
|
|
|
|
void test_incompatible_initializer(void) {
|
|
auto s1[] = "test"; // expected-error {{cannot use 'auto' with array in C}}
|
|
auto s2[4] = "test"; // expected-error {{cannot use 'auto' with array in C}}
|
|
auto s3[5] = "test"; // expected-error {{cannot use 'auto' with array in C}}
|
|
auto i = { 1 }; // expected-error {{cannot use 'auto' with initializer list in C}}
|
|
auto i2 = { 1, 2 }; // expected-error {{cannot use 'auto' with initializer list in C}}
|
|
}
|