Monday, 15 March 2010

c++ - Compiler error initializing std::array of structs with clang -



c++ - Compiler error initializing std::array of structs with clang -

i have code:

std::array<jninativemethod, 26> methods = { { "nativecreate", "(ljava/lang/string;)j", reinterpret_cast<void*>(&nativecreate) }, { "nativedestroy", "(j)v", reinterpret_cast<void*>(&nativedestroy) }, ... { "nativetoggledebug", "(j)v", reinterpret_cast<void*>(&nativetoggledebug) }} };

that trying compile android ndks clang 3.4 compiler.

however code gives me error:

jni/jni.cpp:252:9: error: excess elements in struct initializer { "nativedestroy", "(j)v", reinterpret_cast<void*>(&nativedestroy) }, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

unless add together set of braces:

std::array<jninativemethod, 26> methods = {{ { "nativecreate", "(ljava/lang/string;)j", reinterpret_cast<void*>(&nativecreate) }, { "nativedestroy", "(j)v", reinterpret_cast<void*>(&nativedestroy) }, ... { "nativetoggledebug", "(j)v", reinterpret_cast<void*>(&nativetoggledebug) }} }};

this seems unusual me after finding give-and-take visual c++: http://social.msdn.microsoft.com/forums/vstudio/en-us/e5ad8fa5-c9e8-4328-a7fa-af7a47ce2492/initialising-a-stdarray-of-structs

i want know if wrong c++11 syntax, or defect in clang 3.4.

is related bug mentioned in initializing simple structs using initializer lists clang

std::array aggregate class containing array; need 2 pairs of braces, 1 around class fellow member initialiser(s), , 1 around array element initialiser(s).

i believe c++14 relax requirement, allowing nested array elements initialised outer initialser list.

c++ c++11 compiler-errors clang stdarray

No comments:

Post a Comment