struct S {
  array<int, 1000>vals;
  constexpr S (int _val): vals ({_ val}) {}
struct T {
  int val;
  static constexpr S stk = S (100);
  // static const S stk = S (100);
  T (int i): val (stk.vals [i]) {}
  void set (int i) {val = stk.vals [i];}

I understand thatstatic const S stk = S (100);is not available for the above code, butstatic constexpr S stk = S (100);I didn't know why using code>did not cause an error.

  • static constexpr S stk = S (100);exist at runtime?
  • T :: stkis used in two places. Willarrayvalsbe generated in two places?
  • Answer # 1


    Does static constexpr S stk = S (100);exist at runtime?

    It exists if

    stkis ODR-used (written, addressed, or bound to a reference). If not, it may not exist.
    In addition, I feel that it was impossible to write without taking a reference, so I think that it will be ODR-use if you bind a real reference or take an address.
    static constexpris implicitly specified asinline, so there is only one entity.