Skip to content

Allow __restrict'ing in array size specification in C++, like C #107256

Open
@eyalroz

Description

@eyalroz

Unfortunately, C++ does not have the ever-so-useful restrict keyword of C. Fortunately, compilers such as clang++ offer a __restrict pseudo-keyword. Unfortunately, that keyword is only offered for pointers, not for array parameters. If we write:

int foo(int a[__restrict 10], int b[__restrict 10]) {
    a[0] += b[0];
    return a[0] + b[0];
}

int bar(int *a, int *b) {
    a[0] += b[0];
    return a[0] + b[0];
}

int baz(int * __restrict a, int * __restrict b) {
    a[0] += b[0];
    return a[0] + b[0];
}

then baz() will be accepted by clang++ as C++, but foo() will not (GodBolt).

Well, foo() should be accepted! Taking array parameters is useful, especially if they are multi-dimensionsional. Without them,

See also this G++ bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97477

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++clang:frontendLanguage frontend issues, e.g. anything involving "Sema"enhancementImproving things as opposed to bug fixing, e.g. new or missing featureextension:clangextension:gnu

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions