[PATCH] D148318: [clang-tidy] Add `performance-avoid-endl` check
Piotr Zegar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 15 07:11:25 PDT 2023
PiotrZSL added inline comments.
================
Comment at: clang-tools-extra/clang-tidy/performance/AvoidEndlEndsCheck.cpp:28
+ declRefExpr(
+ to(namedDecl(hasAnyName("endl", "ends")).bind("decl")))
+ .bind("expr")))),
----------------
njames93 wrote:
> Why are you matching on `ends`.
> That manipulator just inserts a null character to the stream(akin to doing `std::cout << '\0';`)
> More to the point changing replacing this call with `std::cout << '\n'` changes behaviour and will likely cause UB as this modifier is meant for null-terminating character buffers to pass to `C` functions.
>
> Double side note the point I made before about how you can turn `<< "World" << endl` into `<< "World\n"` also wouldn't work here as `<< "World\0"` does the same thing as `<< "World"` due to "World" already being a null terminated string.
Good point, so maybe lets get rid `std::ends`, probably that could be covered in different check. I personalty for my project got ends and endl on forbidd list, but thats more to avoid control characters in logs, we can probably create new check for that case, and don't change this one.
Sorry for confusion...
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D148318/new/
https://reviews.llvm.org/D148318
More information about the cfe-commits
mailing list