0

The problem

I'm running clang-tidy on Ubuntu jammy locally and in GitHub Actions. The problem is that I get different behavior in these environments for the following code, where MyType is trivially-copyable:

void MyClass::setField(MyType value) {
  field_ = value;
}

In GitHub Actions I get the following error from clang-tidy:

error: parameter 'value' is passed by value and only copied once; consider moving it to avoid unnecessary copies [performance-unnecessary-value-param,-warnings-as-errors]

Locally this error doesn't appear and if I apply the suggested change (by adding std::move), I get the following error:

error: std::move of the variable 'value' of the trivially-copyable type 'MyType' has no effect; remove std::move() [performance-move-const-arg,-warnings-as-errors]

Environments

clang-tidy-17 is installed like so:

wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository -y "deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy main"
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install clang-tidy

clang-tidy --version prints Ubuntu LLVM version 17.0.0 Optimized build in both environments, so it should be the same version of clang-tidy-17.

The command I run clang-tidy with is: run-clang-tidy -p build -extra-arg=-std=c++17 -quiet <files to scan> -- it uses the .clang-tidy config I have in the repository, so clang-tidy should receive the same arguments. The contents of the config are:

Checks: 'android-*,bugprone-*,google-*,modernize-*,performance-*,portatibility-*,readability-*,-bugprone-easily-swappable-parameters,-modernize-use-trailing-return-type,-readability-identifier-length'
WarningsAsErrors: 'android-*,bugprone-*,clang-analyzer-*,google-*,performance-*,portatibility-*,readability-*'

The compiler I use in both environments is GNU 11.3.0.

Why does this happen? For me it seems like the behavior I get locally is the right one and I would prefer to also see it in CI.

Eyjafl
  • 1,046
  • 6
  • 14

1 Answers1

0

It turned out that an additional library that was linked to my code in CI but not locally influenced clang-tidy in this way. I'm still not sure what exactly changes that makes applying std::move more efficient, though.

Eyjafl
  • 1,046
  • 6
  • 14