使用clang初始化std :: array结构的编译器错误

ljb*_*ade 2 c++ compiler-errors clang c++11 stdarray

我有一些代码:

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) }}
};
Run Code Online (Sandbox Code Playgroud)

我试图用Android NDKs clang 3.4编译器编译.

但是,该代码给了我这个错误:

jni/JNI.cpp:252:9: error: excess elements in struct initializer
        { "nativeDestroy", "(J)V", reinterpret_cast<void*>(&nativeDestroy) },
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)

除非我添加另一组括号:

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) }}
}};
Run Code Online (Sandbox Code Playgroud)

这对我来说似乎很奇怪,但在找到关于Visual C++的讨论后:http: //social.msdn.microsoft.com/forums/vstudio/en-US/e5ad8fa5-c9e8-4328-a7fa-af7a47ce2492/initialising-a-stdarray-的-结构

我想知道这是不正确的C++ 11语法,还是仅仅是clang 3.4中的缺陷.

它是否与使用带有clang的初始化列表初始化简单结构中提到的错误有关

Mik*_*our 7

std::array是包含数组的聚合类; 所以你需要两对括号,一对围绕类成员初始化器,另一对围绕数组元素初始化器.

我相信C++ 14将放宽这个要求,允许嵌套数组元素从外部初始化列表初始化.