66 lines · c
1// RUN: %clang_cc1 -std=c2x -Wall -pedantic -verify %s2// RUN: %clang_cc1 -std=c17 -Wall -pedantic -verify %s3 4/* WG14 N2607: Partial5 * Compatibility of Pointers to Arrays with Qualifiers6 *7 * FIXME: We consider this partially implemented because there are still issues8 * with the composite type from a conditional operator. Further, we don't issue9 * any diagnostics in C17 or earlier when we need at least a pedantic10 * diagnostic about the type incompatibilities.11 */12 13void matrix_fun(int N, const float x[N][N]);14void test1(void) {15 int N = 100;16 float x[N][N];17 // FIXME: This is OK in C23 but should be diagnosed as passing incompatible18 // pointer types in C17 and earlier.19 matrix_fun(N, x);20}21 22#define TEST(Expr, Type) _Generic(Expr, Type : 1)23 24void test2(void) {25 typedef int array[1];26 array reg_array;27 const array const_array = { 0 };28 29 // An array and its elements are identically qualified. We have to test this30 // using pointers to the array and element, because the controlling31 // expression of _Generic will undergo lvalue conversion, which drops32 // qualifiers.33 (void)_Generic(®_array, int (*)[1] : 1);34 (void)_Generic(®_array[0], int * : 1);35 36 (void)_Generic(&const_array, const int (*)[1] : 1);37 (void)_Generic(&const_array[0], const int * : 1);38 39 // But identical qualification does *not* apply to the _Atomic specifier,40 // because that's a special case. You cannot apply the _Atomic specifier or41 // qualifier to an array type directly.42 _Atomic array atomic_array; // expected-error {{_Atomic cannot be applied to array type 'array'}}43 _Atomic(array) also_atomic_array; // expected-error {{_Atomic cannot be applied to array type 'array'}}44 45 // Ensure we support arrays of restrict-qualified pointer types.46 int *restrict array_of_restricted_ptrs[1];47 int *restrict md_array_of_restricted_ptrs[1][1];48}49 50void test3(void) {51 // Validate that we pick the correct composite type for a conditional52 // operator in the presence of qualifiers.53 const int const_array[1] = { 0 };54 int array[1];55 56 // FIXME: the type here should be `const int (*)[1]`, but for some reason,57 // Clang is deciding it's `void *`. This relates to N2607 because the58 // conditional operator is not properly implementing 6.5.15p7 regarding59 // qualifiers, despite that wording not being touched by this paper.60 // However, it should get a pedantic diagnostic in C17 about use of61 // incompatible pointer types.62 (void)_Generic(1 ? &const_array : &array, const int (*)[1] : 1); /* expected-error {{controlling expression type 'void *' not compatible with any generic association type}}63 expected-warning {{pointer type mismatch ('const int (*)[1]' and 'int (*)[1]')}}64 */65}66