llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.15k stars 12.03k forks source link

[Clang Tidy] performance-avoid-endl converts std::endl to '\n' even when preceded by another constant string #76740

Open battre opened 10 months ago

battre commented 10 months ago

clang-tidy -checks=performance-avoid-endl -fix converts std::endl to '\n' even when preceded by another constant string.

Minimum Test case:

#include <iostream>

void foo() {
  std::cerr << "Hello World!" << std::endl;
}

Observed behavior

After running clang-tidy -checks=performance-avoid-endl -fix main.cc the file looks as follows:

#include <iostream>

void foo() {
  std::cerr << "Hello World!" << '\n';
}

Expected output

I think it would make sense to generate

#include <iostream>

void foo() {
  std::cerr << "Hello World!\n";
}
llvmbot commented 10 months ago

@llvm/issue-subscribers-clang-tidy

Author: Dominic Battre (battre)

`clang-tidy -checks=performance-avoid-endl -fix` converts `std::endl` to `'\n'` even when preceded by another constant string. # Minimum Test case: ``` #include <iostream> void foo() { std::cerr << "Hello World!" << std::endl; } ``` # Observed behavior After running `clang-tidy -checks=performance-avoid-endl -fix main.cc` the file looks as follows: ``` #include <iostream> void foo() { std::cerr << "Hello World!" << '\n'; } ``` # Expected output I think it would make sense to generate ``` #include <iostream> void foo() { std::cerr << "Hello World!\n"; } ```
PiotrZSL commented 10 months ago

It would make sense, but check works as documented.