Skip to content

[c2cpg] Proper C++ constructor calls #5486

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

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

Conversation

max-leuthaeuser
Copy link
Contributor

@max-leuthaeuser max-leuthaeuser commented May 13, 2025

This PR adds support for C++ constructors and constructor calls.
See: https://en.cppreference.com/w/cpp/language/constructor

Both constructors and C++17 style member initializer lists are supported.

This includes but is not limited to the following improvements:

  • detect methods that are constructors (was missing before)
  • provide the implicit this parameter
  • create member initialization in those methods incl. synthetic this access if needed
  • create proper calls (i.e., call methodFullNames) to constructors for new expressions as well es initializer list syntax expressions
  • also create calls to default constructors if needed. E.g.,:
S s;      // calls S::S()
S s2(10); // calls S::S(int)
  • handle externally defined constructors by putting them under the proper TypeDecl in a later pass. E.g.,:
class Foo {
  public:
    Foo(int i) {};
};

Foo::Foo(int i, int j) {}; // will be put under Foo 
Bar::Bar(float x) {}; // Bar is not defined at all; keep it here so no dangling methods

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

Successfully merging this pull request may close these issues.

1 participant