3

C++20 introduced constinit to avoid static initialization order fiasco.

Can constinit waive the need for the nifty counter idiom (e.g. for initialization of std::cout)?

Barry
  • 247,587
  • 26
  • 487
  • 819
Amir Kirsh
  • 8,021
  • 22
  • 43
  • 1
    `constinit` doesn't stop static initialization order fiasco. It's used to say that the variable must be constant or zero initialized. i.e `consinit int foo;` would be an error but `constinit int foo = 42;` would not be. – NathanOliver Mar 17 '20 at 13:46

1 Answers1

4

Can C++20 constinit waive the need for nifty counter idiom?

No.

Static initialisation order fiasco is only a problem with dynamic initialisation phase of static objects. Sure, if you don't do dynamic initialisation, then there is no problem, and constinit enforces that. But that doesn't solve anything when you need dynamic initialisation.

eerorika
  • 181,943
  • 10
  • 144
  • 256