Skip to content

Instantly share code, notes, and snippets.

@estan
Created December 1, 2019 13:41
Show Gist options
  • Save estan/5cb8b7f77b35a21f5ed9aedd4b9d0fa2 to your computer and use it in GitHub Desktop.
Save estan/5cb8b7f77b35a21f5ed9aedd4b9d0fa2 to your computer and use it in GitHub Desktop.
Unsetting CMAKE_CXX_CLANG_TIDY before adding subdirectory
#include <cstdio>
int main() { int *a; if (a == NULL) return 0; return 1; } // clang-analyzer-core.UndefinedBinaryOperatorResult
cmake_minimum_required(VERSION 3.10)
project(tidytest)
set(CMAKE_CXX_VERSION 17)
add_executable(app app.cpp)
unset(CMAKE_CXX_CLANG_TIDY)
add_subdirectory(lib)
add_library(lib STATIC lib.cpp)
#include <cstdio>
int foo() { int *a; if (a == NULL) return 0; return 1; } // clang-analyzer-core.UndefinedBinaryOperatorResult
estan@edison:~/tidytest$ mkdir build
estan@edison:~/tidytest$ cd build/
estan@edison:~/tidytest/build$ cmake -DCMAKE_CXX_CLANG_TIDY=clang-tidy-8 ..
-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/estan/tidytest/build
estan@edison:~/tidytest/build$ make
Scanning dependencies of target app
[ 25%] Building CXX object CMakeFiles/app.dir/app.cpp.o
/home/estan/tidytest/app.cpp:2:28: warning: The left operand of '==' is a garbage value [clang-analyzer-core.UndefinedBinaryOperatorResult]
int main() { int *a; if (a == NULL) return 0; return 1; } // clang-analyzer-core.UndefinedBinaryOperatorResult
^
/home/estan/tidytest/app.cpp:2:14: note: 'a' declared without an initial value
int main() { int *a; if (a == NULL) return 0; return 1; } // clang-analyzer-core.UndefinedBinaryOperatorResult
^
/home/estan/tidytest/app.cpp:2:28: note: The left operand of '==' is a garbage value
int main() { int *a; if (a == NULL) return 0; return 1; } // clang-analyzer-core.UndefinedBinaryOperatorResult
^
[ 50%] Linking CXX executable app
[ 50%] Built target app
Scanning dependencies of target lib
[ 75%] Building CXX object lib/CMakeFiles/lib.dir/lib.cpp.o
/home/estan/tidytest/lib/lib.cpp:2:27: warning: The left operand of '==' is a garbage value [clang-analyzer-core.UndefinedBinaryOperatorResult]
int foo() { int *a; if (a == NULL) return 0; return 1; } // clang-analyzer-core.UndefinedBinaryOperatorResult
^
/home/estan/tidytest/lib/lib.cpp:2:13: note: 'a' declared without an initial value
int foo() { int *a; if (a == NULL) return 0; return 1; } // clang-analyzer-core.UndefinedBinaryOperatorResult
^
/home/estan/tidytest/lib/lib.cpp:2:27: note: The left operand of '==' is a garbage value
int foo() { int *a; if (a == NULL) return 0; return 1; } // clang-analyzer-core.UndefinedBinaryOperatorResult
^
[100%] Linking CXX static library liblib.a
[100%] Built target lib
estan@edison:~/tidytest/build$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment