1

If I use clang 3.8.1 to compile:

extern "C" {
int foo(int x) { register int y = x; return y; }
}

int main() { return foo(123); }

I get the warning:

a.cpp:3:18: warning: 'register' storage class specifier is deprecated and incompatible with C++1z [-Wdeprecated-register]
int foo(int x) { register int y = x; return y; }
                 ^~~~~~~~~

... which I really shouldn't be getting this, since the inner function is C code. If I use GCC 6.3.1, even with -Wall, I don't get this warning.

Is this a clang bug or am I doing something wrong?

einpoklum
  • 118,144
  • 57
  • 340
  • 684

2 Answers2

8

extern "C" does not mean "compile this code as C". It means "make this function (or functions) callable from C code", which typically means changing name mangling and, sometimes, calling convention.

Pete Becker
  • 74,985
  • 8
  • 76
  • 165
0

Perhaps the error has nothing to do with the extern "C"? It looks like it says, not, "register is incompatible with C" but rather "register is incompatible with C++1z". (I assume C++1x means C++11/14/17.)

Swiss Frank
  • 1,985
  • 15
  • 33