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.
0
Upvotes
View all comments
Show parent comment
4
u/aruisdante Mar 20 '26 edited Mar 20 '26
A very large number of coding standards require you to avoid shadowed names, even if no actual shadowing occurs. The worst are the ones like MISRA/AutoSAR which require the moral equivalent of
-Wshadow=pedanticcombined with-Werror, meaning that any name at any scope can arbitrarily case a shadowing conflict at any time with any other name in all codebases that interact with each other unless literally every type of symbol has a different naming convention. Nothing beats adding a new free function and discovering-Wshadowerrors for every local variable in the codebase that happened to have that same name, even when they’re all used in contexts that are completely unambiguous.This proposal seems to be a reaction to those rules, but misunderstanding the premise, does not actually solve the problem.
I think MISRA2023 finally makes this rule more sane, allowing instead the equivalent of
-Wshadow=local, the one that actually avoids meaningful shadowing.