4

I am building a C++ project using clang-tidy as linter (cmake -DCMAKE_CXX_CLANG_TIDY=clang-tidy).

After updating my system (Fedora 28->29, cmake 3.11->3.12 I believe), I cannot build any more when clang-tidy reports some clang-diagnostic-error (which I cannot fix right now...). I am pretty sure that clang-diagnostic-error's did not interrupt the build earlier... But I cannot be hundred percent sure.

Edit: The change happened in clang-tidy, now it returns a non-zero exit code when errors are found.

Is it possible to suppress those errors, something like the opposite of "-warnings-as-errors"?

Sergio Losilla
  • 730
  • 1
  • 5
  • 14
  • 1
    Did the version of clang-tidy change? You should expect clang-tidy to improve over time and add new checks – Justin Oct 31 '18 at 20:19
  • Yes it did, but the check was already in place. I would not think that clang-tidy would change its exit code, but I might be wrong... – Sergio Losilla Oct 31 '18 at 21:53
  • Actually, you were right! clang-tidy now returns a different exit status. https://reviews.llvm.org/D45258 – Sergio Losilla Nov 01 '18 at 13:45
  • 1
    Rather than edit it into the question, that may be better as an answer, especially if you found a way to make it work with the changes to clang-tidy – Justin Nov 01 '18 at 15:29
  • You are right, but it would be nice if someone could say if there is some way to have cmake ignore the exit status. – Sergio Losilla Nov 02 '18 at 07:28

1 Answers1

1

Not sure if a solution or a workaround, but this does the trick (in my OS...):

cmake -DCMAKE_CXX_CLANG_TIDY="${PATH_TO_SCRIPT}/suppress_exit_status.sh;clang-tidy"

PATH_TO_SCRIPT to script is the absolute path to suppress_exit_status.sh, which looks like:

#!/bin/sh
$@||echo Command \"$@\" failed with exit code $?

|| is the "or" operator, the second operands is only executed if the first one fails. It seems that cmake captures standard error from the command and throws it way, hence the error message.

I could not figure out a more elegant way to do this, it is not possible to throw || directly into CMAKE_CXX_CLANG_TIDY.

Sergio Losilla
  • 730
  • 1
  • 5
  • 14