在 Android 项目中禁止使用 static_assert

Use of static_assert forbidden in Android project

我正在将一些 C++ 代码移植到 Android。其中一个源文件包含一个 webrtc 头文件,该文件在编译期间会导致错误。我已将问题简化为这个简单的代码:

template <class T, int n>
struct DefaultDeleter<T[n]> {
  // Never allow someone to declare something like scoped_ptr<int[10]>.
 static_assert(sizeof(T) == -1, "do not use array with size as type");
};

我得到的错误是:

[armeabi-v7a] Compile++ thumb: dummyclient <= dummy.cpp
dummy.cpp:7:3: warning: identifier 'static_assert' will become a keyword in C++0x [-Wc++0x-compat]
dummy.cpp:5:8: error: 'DefaultDeleter' is not a template
dummy.cpp:7:17: error: expected identifier before 'sizeof'
dummy.cpp:7:17: error: expected ',' or '...' before 'sizeof'
dummy.cpp:7:70: error: ISO C++ forbids declaration of 'static_assert' with no type [-fpermissive]

相同的代码在 Windows 和 Linux 上编译得很好。 Android 是否需要一些编译器设置?问候。

您需要传递 CPPFLAG -std=c++11