Skip to content

Cpp Support

Derek Snider edited this page Jul 23, 2026 · 1 revision

C++ Support

madc is a C/C++ dialect: C++ features are lowered Cfront-style to plain C11 inside the compiler, then compiled by the same MIR backend as everything else. That means C++ programs work in every mode — JIT, native executables, --emit=c11 C source output — with no separate C++ runtime.

The C++ surface has grown far beyond the early days. What works today:

Classes

  • Constructors, destructors, copy constructors — including the implicit memberwise copy constructor for classes that never declared one (nested members with their own copy constructors are deep-copied correctly)
  • Methods (including const methods), this, member access control
  • Operator overloading — arithmetic, comparison, subscript, and the C++20 three-way comparison <=> (spaceship) with synthesized relationals
  • References (T&) as parameters, returns, and members
  • new / delete with constructor/destructor invocation
  • RAII — destructors run at every scope exit, return, and exception unwind

Inheritance

  • Single, multiple, and virtual inheritance with the Itanium C++ ABI layout — thunks, virtual bases constructed exactly once
  • Virtual functions and virtual destructors (complete D1/D0 semantics)
  • RTTI and dynamic_cast

Templates

  • Class templates, function templates, and member function templates with real monomorphization — each instantiation compiles to concrete native code
  • The pattern is parsed once and instantiated by substitution (the same model g++ uses), so heavy template code stays fast to compile
  • Template-id casts ((Box<int>)x), alias templates, default arguments

Exceptions

  • try / catch / throw with type-dispatched catch clauses, lowered to portable C (setjmp/longjmp) so they work in every output mode

Standard library interop

  • std::string, std::stringstream, cout/cin/cerr are real libstdc++ objects — madc calls the actual mangled Itanium symbols in your system's libstdc++, not reimplementations
  • vector<T>, map<K,V>, set<T>, list<T> with madc-side template instantiation
  • Real system headers (<iostream>, etc.) can be consumed directly

Modern conveniences

  • Lambdas with [&] captures (and GNU nested functions)
  • auto, range-based for, trailing return types
  • namespace / using
  • --std=c++NN gates dialect features the same way --std=c89c23 does for C

What's not there (yet)

madc does not claim complete C++. Notable gaps: pure virtual functions, std::function / unique_ptr and broad <algorithm> coverage, and wchar_t/wide strings. The north star is C23/C++23 compliance — coverage grows every release.

What's next?

Clone this wiki locally