Search code examples
c++multilingualclang++extern-c

Is clang++ ignoring extern "C" for some deprecation warnings?


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?


Solution

  • 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.