clang++ 是否支持__restrict

Does clang++ support __restrict?

本文关键字:restrict 支持 是否 clang++      更新时间:2023-10-16

以下代码使用 g++ 4.7.1 编译,但不能使用 clang 3.1 编译

struct A
{
  int foo();
};
int A::foo() __restrict
{
  return 0;
}

int main(int argc, char * argv[])
{
  A a;
  return a.foo();
}

clang 是否支持__restrict?还是使用特定的语法?

我手边没有 clang 3.1,但在 clang 4.1 下,我收到此错误:

t.cpp:6:8: error: out-of-line definition of 'foo' does not match any declaration
      in 'A'
int A::foo() __restrict
       ^~~
t.cpp:3:7: note: member declaration nearly matches
  int foo();
      ^
1 error generated.

如果我将 A::foo 的声明更改为以下内容,则 clang 4.1 成功编译它:

  int foo() __restrict;