fuchsia-statically-constructed-objects

如果全局、非平凡对象具有静态存储,则发出警告,除非该对象使用 constexpr 构造函数进行静态初始化,或者没有显式构造函数。

例如

class A {};

class B {
public:
  B(int Val) : Val(Val) {}
private:
  int Val;
};

class C {
public:
  constexpr C(int Val) : Val(Val) {}
  C(int Val1, int Val2) : Val(Val1+Val2) {}

private:
  int Val;
};

static A a;         // No warning, as there is no explicit constructor
static C c(0);      // No warning, as constructor is constexpr

static B b(0);      // Warning, as constructor is not constexpr
static C c2(0, 1);  // Warning, as constructor is not constexpr

static int i;       // No warning, as it is trivial

extern int get_i();
static C c3(get_i());// Warning, as the constructor is dynamically initialized

有关 Fuchsia 中禁止的功能,请参阅 https://fuchsia.dev/fuchsia-src/development/languages/c-cpp/cxx?hl=en