Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object constructor not called on global static objects #180

Open
Blackhex opened this issue Aug 14, 2024 · 1 comment
Open

Object constructor not called on global static objects #180

Blackhex opened this issue Aug 14, 2024 · 1 comment
Labels
C++ C++ Support

Comments

@Blackhex
Copy link
Member

Blackhex commented Aug 14, 2024

Considering the following C++ code:

#include <cstdio>

class C {
public:
  C(const char *s) {
    printf(s);
  }
};

static C b("b");

namespace D {
  static C d("d");
}

int main(int argc, char **argv) {
  static C c("c");
  C a("a");
}

It outpus ca instead of bdca (or whatever is the order defined by the standard) which means that the constructors for global static objects are not called (both namespaces and non-namespaced). The local static objects' constrcutor get called.

@Blackhex Blackhex changed the title Object constructor not called on static objects Object constructor not called on global static objects Aug 14, 2024
@Blackhex Blackhex added the C++ C++ Support label Aug 14, 2024
@Blackhex
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ C++ Support
Projects
None yet
Development

No branches or pull requests

1 participant