C++ - Reddit
226 subscribers
48 photos
8 videos
24.6K links
Stay up-to-date with everything C++!
Content directly fetched from the subreddit just for you.

Join our group for discussions : @programminginc

Powered by : @r_channels
Download Telegram
splice: a C++26 reflection-based hook and signal library

I’ve been experimenting with static reflection in the gcc16 trunk. I’ve built a library that lets you annotate class/struct methods and inject behavior through attributes.

You mark methods as hookable with [[=splice::hook::hookable{}]], then you can inject before/after/return hooks at runtime through a registry. You can cancel calls, override return values, rewrite arguments and control execution order by changing the priority of your hooks, all without touching the original class.

It also has a wire system for signal/slot connections. Slots declare which signal they handle via reflection attributes, and you can connect specific, or all signals on a listener. Listeners can also be paused, resumed, and they automatically disconnect when destroyed via RAII. If you want to wire a listener to for example, an on_click method on a class, you just add an attribute: [[SPLICE_WIRE_SLOT(.signal = ^^MyClass::on_click)]]

This currently requires GCC 16 (built from a snapshot) and the -freflection compiler flag. Still early, but all the tests pass and the API feels simple to use. Eventually, I want to use the same reflection machinery to generate FFI bindings for Lua, and maybe other scripting languages too.

GitHub: https://github.com/FloofyPlasma/splice

Curious if anyone else is experimenting with the reflection coming in C++ 26.

https://redd.it/1rxj838
@r_cpp
C++26: Span improvements and freestanding.

Given the freestanding remarks at https://www.sandordargo.com/blog/2026/03/18/cpp26-span-improvements blog post.

> As freestanding environments generally cannot support exceptions, parts of these facilities cannot be included. Specifically, span::at() (since it throws std::outofrange) and all overloads of std::expected::value() are excluded from the freestanding subset.

It appears that once again, even with C++26 hardening runtime, there were some security improvements that were left out of the table when targeting freestanding environments.

Like possibly having some try_at() that would return std::optional or std::expected result types.

At least looking at the proposed std::span I am not able to find such alternatives.

https://redd.it/1rwznpr
@r_cpp
What open source projects in C++ have the highest code quality?

My understanding of the characteristics of quality code are the conventional ones.

* operations on an object that are allowed in a particular object state do not put the object into an invalid state.
* it's prioritized to organize the implementation of each object into the smallest possible number of sub-objects.
* no cryptically abbreviated names are used, except possible in very small scopes.

With the program(s)/executable(s) themselves, as well as modules with corresponding namespaces, being considered singleton objects.

Fair dinkum if you want to name projects that score well under a different understanding of code quality.

https://redd.it/1rwokuj
@r_cpp
Draft idea: constructor member designators

I’ve been experimenting with a small idea to make constructor initializer lists a bit clearer and less error‑prone. The idea actually came from a dilemma I had when trying to settle on naming conventions for member variables. Prefixes like m_ or _name help avoid shadowing, but they also feel like a workaround for something the language could express more directly.

I wrote a short draft exploring “constructor member designators” - a `.member` syntax for constructor initialization.

https://github.com/richardcervinka/cpp-constructor-member-designators

This is just an experiment, but maybe someone will find it interesting.

https://redd.it/1ryyizp
@r_cpp
C++/sys - A Standard Library Projection to Facilitate the Verification of Run-time Memory Safety

Hi all,

A while ago I was looking for a relevant C++ conference to demonstrate the capabilities of C++/sys. A pure C++ mechanism which offers a new approach to memory safety via debug-time verification.

My talk was accepted into C++Online 2026 which concluded a couple of weeks ago. The discussions were great, I received some really useful feedback (and the little 2D gather town was pretty fun!).

The slides are available here and the release video should appear on YouTube in the following weeks.

Excited to share the tech with the wider community. Much of it is discussed in the slides; some highlights:

Offers improvements over AddressSanitizer in terms of C++ error detection rate
Tracks access lifespan rather than blocks of data
Has contextual knowledge of C++ objects and containers so generally quite performant
100% detection rate for executed paths
Memory pinning and locking mechanism tracks dangling 'this' and references
Zero overhead in release builds
Compatible with any standard C++ compiler (from hosted C++98 running on MS-DOS to freestanding C++${LATEST} on Zephyr)
Doesn't interfere with C code/libraries. Just like Java, Rust, Python thin-bindings, these are treated as unchecked.

Some of the above sounds like magic but the core mechanism allowing for this is quite simple. Temporaries created by operator->, operator* and operator[\] lock memory for the lifetime of access and pointers are entirely prevented from dangling in a coarse-grained manner. Obviously this has an impact on what designs are possible with some discussion in the slides.

Link to the open-source (BSD 3-clause) reference implementation is here.

https://codeberg.org/kpedersen/sys\_public

https://research.thamessoftware.co.uk/sys

Very happy to discuss further. It has some rough areas but I personally love the tech and find it makes writing and testing C++ considerably more satisfying knowing that there is virtually zero chance of a memory error lurking in the tested branches.



https://redd.it/1rz3df4
@r_cpp
A matter of style or is it?

Which one do you prefer (the constructor does some work and sets valid_):

class A {
public:
explicit operator bool() const { return valid; }

private:
bool valid_ = false;
}


or

class A {
public:
bool is_valid() const { return valid; }

private:
bool valid_ = false;
}


On the caller side:

A a{};
if (a) {
// is valid
}


or

A a{}
if (a.is_valid()) {
// is valid
}


https://redd.it/1rz8gq5
@r_cpp
Should assertions be used frequently in software development? And in what general scenarios are they typically applied?



https://redd.it/1rzfy9i
@r_cpp
Last C++26 meeting in Croydon is about to begin

Since not everyone is aware and confusion often arises regarding privated GitHub repos, let's inform people on Reddit this time: The last meeting for C++26 is about to begin. Some quick facts:

- The meeting lasts from 2026-03-23 (Mon morning) to 2026-03-28 (Sat afternoon). See also <https://isocpp.org/std/meetings-and-participation/upcoming-meetings>
- Until the meeting ends, <https://github.com/cplusplus/papers/> is private. The repos usually become visible again immediately after the meeting ends.
- The papers published during and after the meeting all go into the April mailing 2026-04-20. This includes the final working draft.
- All remaining NB (national body) comments should be resolved during this meeting. The working draft is then sent off to ISO for review and national bodies vote on the C++26 standard as a whole (yes/no/abstain).
- Any C++26 work takes priority, but once that is completed, time is spent on C++29 papers.

https://redd.it/1rzjovp
@r_cpp
Standard LLMs hallucinate on large C++ codebases. I built an open-source MCP server using tree-sitter to fix that.

I’ve been experimenting heavily with AI agents for legacy modernization, but I kept hitting a massive wall when dealing with C++.

If you just dump a bunch of intertwined C++ files into Claude or an open-source model, it loses context. It tries to refactor a function without knowing what upstream dependencies rely on it, or it gets tangled in circular references and breaks the build. Regex-based parsers also constantly miss the nuances of C++ macros and templates.

So, I built **LegacyGraph-MCP**, an open-source Model Context Protocol (MCP) server that turns "spaghetti code" into a queryable Knowledge Graph for AI Agents.

**How it works under the hood:** Instead of forcing the LLM to read raw text and guess relationships, the agent queries the structure.

1. **AST Parsing:** It uses `tree-sitter-cpp` for 100% accurate parsing (no regex hacks).
2. **Graph RAG:** It loads the codebase into a NetworkX directed graph.
3. **Agent Interaction:** The LLM uses MCP tools to ask specific questions like:
* *“Which functions call* `process_client()`\*?”\*
* *“Are there any circular dependencies here?”*
* *“What are the orphan functions?”*

**Features:**

* **Omni-Ingestion:** It can clone a GitHub repo, apply a patch, scan a local directory, or accept raw file uploads.
* **Hybrid Deployment:** You can run it locally (`stdio`) directly tied to your IDE/Claude Desktop, or deploy it to the cloud (`HTTP`/`SSE`) with ephemeral `/tmp/` clones.
* **Token-Safe Visuals:** It dynamically generates bounded Mermaid.js graphs inline so the LLM can visually map out the dependencies it is working on.

**The Ask:** The core graph logic is working well (I’ve got an end-to-end verifier passing 100% on test data), but I’m looking for feedback from people who work with *really* messy, real-world legacy code.

Specifically:

1. Does the cycle detection logic hold up against your worst circular dependencies?
2. Are there specific query tools (besides `get_callers`, `get_callees`, `detect_cycles`, etc.) that would make your life easier when using an AI coding assistant?

**Repository:** [LegacyGraph-MCP](https://github.com/RohitYadav34980/LegacyGraph-MCP)

*(If you are using Smithery or Claude Desktop, I included the quick-start configs in the README).*

What else can we build with this?
I am open to all ideas! Could we use this for automated test scaffolding for isolated subgraphs? Dead-code pruning pipelines? Vulnerability blast-radius analysis? Drop your ideas in the comments.

Whether you are a backend engineer optimizing graph algorithms, or someone pushing the limits of AI agents, there is a place for you here. Let’s build the ultimate open-source legacy modernization engine together.


Would love to hear your thoughts or see if this breaks on your weirdest legacy code!

https://redd.it/1rzws51
@r_cpp