0

The following code compiles with g++ 4.7.1 but not clang 3.1

struct A
{
  int foo();
};

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


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

Does clang support __restrict? or is it using a particular syntax?

qdii
  • 12,505
  • 10
  • 59
  • 116

1 Answers1

2

I don't have clang 3.1 handy, but under clang 4.1, I get this error:

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.

clang 4.1 compiles it successfully if I change the declaration of A::foo to this:

  int foo() __restrict;
rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • clang 3.1 gives the same error. But okay, that’s good to know. – qdii Oct 06 '12 at 03:04
  • 1
    There is a Clang 4.1? The latest builds from the trunk are numbered 3.2; is development being done somewhere other than the trunk? – James McNellis Oct 06 '12 at 03:05
  • Xcode 4.5 includes clang 4.1. The `-v` output is `Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)`. – rob mayoff Oct 06 '12 at 03:05
  • 2
    Oh; it looks like Apple is using their own version numbers. That's kind of weird. – James McNellis Oct 06 '12 at 03:08
  • @JamesMcNellis: yes it is, causes no end of troubles when people come reporting bugs too :( – Matthieu M. Oct 06 '12 at 13:01
  • Apple used to directly base their version number on whatever the version happened to be on the trunk when they imported changes. So if the last import was during development of 3.0 but before llvm.org's official 3.0 release then Apple's version would have that version number but wouldn't match up with the features listed by llvm.org for that release. – bames53 Oct 29 '12 at 18:43
  • It's better that Apple is no longer doing that, but you should still always remember to clarify the version number when you're referring to Apple's version; e.g. Apple clang 4.1, or LLVM compiler 4.1 (clang is only referred to as 'the LLVM compiler' by Apple), whereas a release from llvm.org will just be unqualified; e.g. clang 3.2. – bames53 Oct 29 '12 at 18:43