Skip to content

Commit 69949c8

Browse files
authored
Merge pull request #54 from cpp-best-practices/clang-tidy-clang-cl
2 parents 3123014 + 6ed5231 commit 69949c8

3 files changed

Lines changed: 37 additions & 44 deletions

File tree

.clang-tidy

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,19 @@
11
---
2-
Checks:
3-
'-*,
4-
cert-*,-cert-err58-cpp,
5-
clang-diagnostic-*,
6-
clang-analyzer-*,
7-
hicpp-*,-hicpp-avoid-c-arrays,-hicpp-no-array-decay,hicpp-explicit-*,-hicpp-use-equals-default,-hicpp-signed-bitwise,-hicpp-special-member-functions,-hicpp-use-equals-delete,
8-
misc-*,-misc-non-private-member-variables-in-classes,
9-
modernize-*,modernize-use-*,modernize-avoid-c-arrays,-modernize-use-trailing-return-type,
10-
performance-*,
11-
portability-*,
12-
readablity-*,
13-
'
14-
WarningsAsErrors: 'clang-analyzer-*'
15-
HeaderFilterRegex: '.*\.hpp$'
16-
AnalyzeTemporaryDtors: false
17-
FormatStyle: file
18-
User: klein_cl
19-
CheckOptions:
20-
- key: google-readability-braces-around-statements.ShortStatementLines
21-
value: '1'
22-
- key: google-readability-function-size.StatementThreshold
23-
value: '800'
24-
- key: google-readability-namespace-comments.ShortNamespaceLines
25-
value: '10'
26-
- key: google-readability-namespace-comments.SpacesBeforeComments
27-
value: '2'
28-
- key: modernize-loop-convert.MaxCopySize
29-
value: '16'
30-
- key: modernize-loop-convert.MinConfidence
31-
value: reasonable
32-
- key: modernize-loop-convert.NamingStyle
33-
value: CamelCase
34-
- key: modernize-pass-by-value.IncludeStyle
35-
value: llvm
36-
- key: modernize-replace-auto-ptr.IncludeStyle
37-
value: llvm
38-
- key: modernize-use-nullptr.NullMacros
39-
value: 'NULL'
40-
...
41-
2+
Checks: "*,
3+
-abseil-*,
4+
-altera-*,
5+
-android-*,
6+
-fuchsia-*,
7+
-google-*,
8+
-llvm*,
9+
-modernize-use-trailing-return-type,
10+
-zircon-*,
11+
-readability-else-after-return,
12+
-readability-static-accessed-through-instance,
13+
-readability-avoid-const-params-in-decls,
14+
-cppcoreguidelines-non-private-member-variables-in-classes,
15+
-misc-non-private-member-variables-in-classes,
16+
"
17+
WarningsAsErrors: ''
18+
HeaderFilterRegex: ''
19+
FormatStyle: none

src/StaticAnalyzers.cmake

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ macro(enable_cppcheck)
88
--enable=style,performance,warning,portability
99
--inline-suppr
1010
--inconclusive)
11-
if(${CMAKE_CXX_STANDARD})
11+
if(NOT
12+
"${CMAKE_CXX_STANDARD}"
13+
STREQUAL
14+
"")
1215
set(CMAKE_CXX_CPPCHECK ${CMAKE_CXX_CPPCHECK} --std=c++${CMAKE_CXX_STANDARD})
1316
endif()
1417
if(WARNINGS_AS_ERRORS)
@@ -31,11 +34,20 @@ macro(enable_clang_tidy)
3134
SEND_ERROR
3235
"clang-tidy cannot be enabled with non-clang compiler and PCH, clang-tidy fails to handle gcc's PCH file")
3336
endif()
34-
37+
# construct the clang-tidy command line
3538
set(CMAKE_CXX_CLANG_TIDY ${CLANGTIDY} -extra-arg=-Wno-unknown-warning-option)
36-
if(${CMAKE_CXX_STANDARD})
37-
set(CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY} -extra-arg=-std=c++${CMAKE_CXX_STANDARD})
39+
# set standard
40+
if(NOT
41+
"${CMAKE_CXX_STANDARD}"
42+
STREQUAL
43+
"")
44+
if("${CMAKE_CXX_CLANG_TIDY_DRIVER_MODE}" STREQUAL "cl")
45+
set(CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY} -extra-arg=/std:c++${CMAKE_CXX_STANDARD})
46+
else()
47+
set(CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY} -extra-arg=-std=c++${CMAKE_CXX_STANDARD})
48+
endif()
3849
endif()
50+
# set warnings as errors
3951
if(WARNINGS_AS_ERRORS)
4052
list(APPEND CMAKE_CXX_CLANG_TIDY -warnings-as-errors=*)
4153
endif()

test/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ int main() {
2727
// trigger address sanitizer
2828
// int *p = nullptr;
2929
// *p = 1;
30+
31+
// trigger compiler warnings, clang-tidy, and cppcheck
32+
int a;
3033
}

0 commit comments

Comments
 (0)