[PATCH] D148318: [clang-tidy] Add `performance-avoid-endl` check

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 15 07:04:24 PDT 2023


njames93 added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/performance/AvoidEndlEndsCheck.cpp:28
+              declRefExpr(
+                  to(namedDecl(hasAnyName("endl", "ends")).bind("decl")))
+                  .bind("expr")))),
----------------
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.


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