c++macoskernel-extensionxnu

Using `decltype` in IOKit code


When compiling IOKit based kernel extension, the c++ compiler cannot recognize the keyword decltype.

int f = 123; 
int (*f_ptr)() = 0; 

f_ptr =  (decltype(f_ptr)) f;

Compiler fail on the code above for reason : Use of undeclared identifier 'decltype'. The auto keyword on the other hand, works as expected.

However, if i compile the exact same code in C++ user-mode application, it works fine.

Any idea why is that ?


Solution

  • decltype require C++11 support. Look at your projects Build Settings and make sure the C++ Language Dialect is at least GNU++11/C++11 or later (search for the -std= option)

    auto on the other hand is an old storage duration specifier keyword re-used in C++11[6].