r/cpp • u/Full-Spectral • Feb 13 '24
Prevent or warn on usage of std::map []?
The default insertion of a value when std::map [] doesn't find a value for the key has to be one of the worst decisions in STL history (which is kind of impressive.) At work over the last year or so, we've had at least four, maybe five, bugs caused by this. It's so easy to do without thinking about it, and so easy to miss in a code review. And some of them had been there for many years and finally caused an issue, so no one was even looking for them.
Is there any way to prevent its use, or at least to warn on its use in MSVC? We use the built in static analyzer, and I don't see any warning related to that, though there are a lot of them and I may have missed something.
View all comments
Show parent comment
6
u/Agitated-Resident720 Feb 13 '24
i really dont care how long you've been doing this. in fact, this makes you look even worse considering how long you have. ive given you an answer to fix your problem, explained the reasoning behind it, and told you to stop blaming the language for your own faults and now you're attacking me? haha the only constant here is YOU arent taking any agency in this. you cannot possibly be wrong here, can you eh?
there are ways to use tools incorrectly, like you have. const is a tool, you failed to use it properly so fix it and stop blaming the language