Skip to content

Details

Introduction:
Encapsulation is a cornerstone of C++, yet private members often pose challenges in real projects. When refactoring legacy code, working with third party libraries, or debugging complex systems, gaining access to internals can be necessary to establish tests and enable a test driven workflow. In these situations, developers inevitably face the question of how to "test the privates" without breaking the rules.

Relevance:
This is not an edge case but a recurring scenario in production code. Developers frequently reach for shortcuts such as #define private public or memory layout tricks. Those shortcuts are mostly undefined behavior leading to portability problems, or even changes in object layout across compilers. There are well known examples in widely used projects where such hacks have caused failures. This talk brings these issues into focus with real world references and demonstrates safer alternatives.

Program:
1. Why developers sometimes need access to private members (legacy code, third party libraries, debugging, instrumentation, and refactoring with TDD).
2. Common techniques to achieve the access
3. Showcase (live) the dangerous side-effects: macro leakage, ABI mismatches, portability failures.
4. Discovering the standard loophole
5. Live coding: step by step demonstration of this technique in practice, with explanations of how it works under the hood.
6. Q&A and open discussion with attendees.

Completion state:
Implementation is ready as github library - cpp-member-accessor

Support materials:
1. https://github.com/nlohmann/json/issues/913 - “error due to #define private public”
2. https://godbolt.org/z/Pjs1Y4cdv - “macro leak, size difference”
3. https://pvs-studio.com/en/blog/posts/0146/ - “Your code can break”
4. “https://eel.is/c++draft/macro.names#2” - “It’s UB”

About Hubert:
Hubert Liberacki is a Lead Software Engineer with over a decade of experience in C++
development across automotive and robotics, focusing on performance-critical and
distributed systems.
At Apex.AI he worked on automotive-grade software-defined vehicle frameworks, and he is
currently working at HERE Technologies on maps and rendering in large-scale C++ projects.
His current interests also include Rust and its applications in high-performance and
distributed systems.

Embedded Systems
Programming Languages
Computer Programming
Software Development
Computer Science

Members are also interested in