45 lines · c
1// RUN: %clang_cc1 -verify -std=c99 %s2// RUN: %clang_cc1 -verify -std=c23 %s3 4/* WG14 N448: Partial5 * Restricted pointers6 *7 * NB: we claim partial conformance only because LLVM does not attempt to apply8 * the semantics on local variables or structure data members; it only9 * considers function parameters. However, Clang itself is fully conforming for10 * this feature.11 */12 13// Restrict is only allowed on pointers.14int * restrict ipr;15int restrict ir; // expected-error {{restrict requires a pointer or reference ('int' is invalid)}}16 17// Restrict only applies to object pointers.18void (* restrict fp)(void); // expected-error {{pointer to function type 'void (void)' may not be 'restrict' qualified}}19 20typedef int *int_ptr;21int_ptr restrict ipr2; // okay, still applied to the pointer.22 23// Show that the qualifer is dropped on lvalue conversion24_Static_assert(25 _Generic(ipr,26 int * : 1,27 int * restrict : 0, // expected-warning {{due to lvalue conversion of the controlling expression, association of type 'int *restrict' will never be selected because it is qualified}}28 default : 0),29 "");30 31// Show that it's allowed as a qualifier for array parameters.32void f(int array[restrict]) {33 int *ipnr = ipr; // okay to drop the top-level qualifier34 35 // Show that it's not okay to drop the qualifier when it's not at the top level.36 int * restrict * restrict iprpr;37 int **ipp = iprpr; // expected-warning {{initializing 'int **' with an expression of type 'int *restrict *restrict' discards qualifiers}}38 int ** restrict ippr = iprpr; // expected-warning {{initializing 'int **restrict' with an expression of type 'int *restrict *restrict' discards qualifiers}}39}40 41#if __STDC_VERSION__ >= 202311L42// C23 doesn't allow constexpr to mix with restrict. See C23 6.7.2p5.43constexpr int * restrict ip; // expected-error {{constexpr variable cannot have type 'int *const restrict'}}44#endif // __STDC_VERSION__ >= 202311L45