4 ms·
Clang gives a warning for the first example: <source>:7:25: warning: object backing the pointer will be destroyed at the end of the full-expression [-Wdangling
by zone411 6y ago
Clang gives a warning for the first example:
<source>:7:25: warning: object backing the pointer will be destroyed at the end of the full-expression [-Wdangling-gsl]
https://godbolt.org/z/zTnjbhMqr https://godbolt.org/z/zTnjbhMqr
- TeMPOraL 6y agoYeah, and clang-tidy gives another; I just typed the first example and got both -Wdangling-gsl and "Std::basic_string_view outlives its value [bugprone-dangling-handle]" from clang-tidy. It doesn't invalidate the point of the article, that these things perhaps should be easier to avoid, or impossible to express. You can code safe-ish C++ with high warnings settings and enough liters and static analysis tools backing you, but it's not ideal experience.
- cflewis 6y agoI changed teams at work (Google) to one that uses a C++ codebase that has survived for 20 years. As someone writing C++ for the first time, clang-tidy has been huge. It stops so many screw ups before I get to the code reviewer. I've not found C++ as bad as I worried, partly because Google's style guide limits the amount of silliness you can do, partly because I have avoided memory issues by just never allocating to the heap using `new` with smart pointers, but mostly because Clang and Clang-Tidy have helped me avoid all the footguns. I wouldn't write a new project in C++ (especially outside Google where the package management ecosystem is non-existant), but I'm no longer of the opinion that I would never join a team just because their current codebase was written in C++.