4

I don't understand why I am getting this warning when I run my code through clang tidy. I think that the error message is telling me that I am using NULL instead of nullptr, but I am not using NULL anywhere.

https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html:

The check converts the usage of null pointer constants (eg. NULL, 0) to use the new C++11 nullptr keyword.

Here is the code that is causing the error:

#include <chrono>


int
main() {
    using Clock = std::chrono::steady_clock;

    auto const time_point = Clock::now();
    auto const x = time_point < Clock::now();

    return static_cast<int>(x);
}

[ 94%] Building CXX object src/CMakeFiles/app.dir/main.cpp.o
/src/main.cpp:9:28: error: use nullptr [hicpp-use-nullptr,-warnings-as-errors]
        auto const x = time_point < Clock::now();
                                  ^
note: this fix will not be applied because it overlaps with another fix
/src/main.cpp:9:28: error: use nullptr [modernize-use-nullptr,-warnings-as-errors]
note: this fix will not be applied because it overlaps with another fix

1563 warnings generated.
Suppressed 1561 warnings (1561 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
2 warnings treated as errors
make[3]: *** [src/CMakeFiles/app.dir/build.make:83: src/CMakeFiles/app.dir/main.cpp.o] Error 2
make[2]: *** [CMakeFiles/Makefile2:258: src/CMakeFiles/app.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:211: CMakeFiles/run.dir/rule] Error 2
make: *** [Makefile:175: run] Error 2
$ uname -a
Linux desktop 5.6.16-1-MANJARO #1 SMP PREEMPT Wed Jun 3 14:26:28 UTC 2020 x86_64 GNU/Linux

$ clang --version
clang version 10.0.0
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ clang-tidy --version
LLVM (http://llvm.org/):
  LLVM version 10.0.0
  Optimized build.
  Default target: x86_64-pc-linux-gnu
  Host CPU: znver2

$ cat .clang-tidy
---
Checks:          '*,-fuchsia-*,-google-*,-zircon-*,-abseil-*,-modernize-use-trailing-return-type,-llvm-*'
WarningsAsErrors: '*'
HeaderFilterRegex: ''
FormatStyle:     none

In my CMakeLists.txt

find_program(CLANGTIDY clang-tidy)
set(CMAKE_CXX_CLANG_TIDY ${CLANGTIDY} -extra-arg=-Wno-unknown-warning-option)
user1032677
  • 363
  • 2
  • 11

0 Answers0