this post was submitted on 30 Nov 2023
-1 points (45.5% liked)

C++

1755 readers
1 users here now

The center for all discussion and news regarding C++.

Rules

founded 1 year ago
MODERATORS
-1
The Myth of Smart Pointers (www.logikalsolutions.com)
submitted 10 months ago by lysdexic to c/cpp
you are viewing a single comment's thread
view the rest of the comments
[โ€“] QuadriLiteral 2 points 10 months ago* (last edited 10 months ago) (1 children)

I agree with what you're saying even though I do think a lot of C++'s bad rep comes either from C or from pre-C++11 code. I also think that modern code should include clang-tidy in the CI, and if so at least simple mistakes like in OPs code would be flagged with "warning: Use of memory after it is freed [clang-analyzer-cplusplus.NewDelete]"

https://clang-tidy.godbolt.org/z/8E169bons

Note that all of the warnings in there are valid and should be fixed, so it's not like wading through a see of false positives. That being said, the post is interesting in its explanation of why the example does what it does. Too bad all of the other stuff in there is bonkers.

[โ€“] 5C5C5C 2 points 10 months ago

Linters are good and should absolutely be used in any serious C++ project, but they can only catch the most basic sources of UB. I almost never make a mistake that a static analyzer can catch. It's the multithreaded lifetime issues and data races that ambush you the hardest, and I don't see any way a C++ static analyzer could hope to catch those.

But yes, most of the original post is bonkers and has the totally wrong conclusion.