Skip to content

Commit 506e15f

Browse files
authored
Merge pull request #13 from StephanKa/feature/update-clang-format-and-tidy
feature/update clang format and tidy
2 parents 97c973e + 8094129 commit 506e15f

26 files changed

Lines changed: 381 additions & 429 deletions

.clang-format

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
AccessModifierOffset: -2
22
AlignAfterOpenBracket: DontAlign
3-
AlignConsecutiveAssignments: false
4-
AlignConsecutiveDeclarations: false
3+
AlignConsecutiveAssignments: None
4+
AlignConsecutiveDeclarations: None
55
AlignEscapedNewlines: Left
66
AlignOperands: true
77
AlignTrailingComments: false
88
AllowAllParametersOfDeclarationOnNextLine: false
9-
AllowShortBlocksOnASingleLine: true
9+
AllowShortBlocksOnASingleLine: Always
1010
AllowShortCaseLabelsOnASingleLine: false
1111
AllowShortFunctionsOnASingleLine: All
1212
AllowShortIfStatementsOnASingleLine: true
1313
AllowShortLoopsOnASingleLine: true
1414
AlwaysBreakAfterDefinitionReturnType: None
1515
AlwaysBreakAfterReturnType: None
1616
AlwaysBreakBeforeMultilineStrings: true
17-
AlwaysBreakTemplateDeclarations: false
17+
AlwaysBreakTemplateDeclarations: No
1818
BinPackArguments: false
1919
BinPackParameters: false
2020
BraceWrapping:
@@ -40,7 +40,7 @@ BreakBeforeTernaryOperators: true
4040
BreakConstructorInitializers: BeforeColon
4141
BreakConstructorInitializersBeforeComma: false
4242
BreakStringLiterals: true
43-
ColumnLimit: 0
43+
ColumnLimit: 180
4444
CommentPragmas: '^ IWYU pragma:'
4545
CompactNamespaces: false
4646
ConstructorInitializerAllOnOneLineOrOnePerLine: false
@@ -52,19 +52,19 @@ DisableFormat: false
5252
ExperimentalAutoDetectBinPacking: true
5353
FixNamespaceComments: true
5454
ForEachMacros:
55-
- foreach
56-
- Q_FOREACH
57-
- BOOST_FOREACH
55+
- foreach
56+
- Q_FOREACH
57+
- BOOST_FOREACH
5858
IncludeCategories:
59-
- Priority: 2
60-
Regex: ^"(llvm|llvm-c|clang|clang-c)/
61-
- Priority: 3
62-
Regex: ^(<|"(gtest|gmock|isl|json)/)
63-
- Priority: 1
64-
Regex: .*
59+
- Priority: 2
60+
Regex: ^"(llvm|llvm-c|clang|clang-c)/
61+
- Priority: 3
62+
Regex: ^(<|"(gtest|gmock|isl|json)/)
63+
- Priority: 1
64+
Regex: .*
6565
IncludeIsMainRegex: (Test)?$
6666
IndentCaseLabels: false
67-
IndentWidth: 2
67+
IndentWidth: 4
6868
IndentWrappedFunctionNames: true
6969
JavaScriptQuotes: Leave
7070
JavaScriptWrapImports: true
@@ -79,7 +79,7 @@ ObjCSpaceAfterProperty: true
7979
ObjCSpaceBeforeProtocolList: false
8080
PointerAlignment: Right
8181
ReflowComments: true
82-
SortIncludes: false
82+
SortIncludes: CaseSensitive
8383
SortUsingDeclarations: false
8484
SpaceAfterCStyleCast: false
8585
SpaceAfterTemplateKeyword: false
@@ -92,7 +92,6 @@ SpacesInCStyleCastParentheses: false
9292
SpacesInContainerLiterals: true
9393
SpacesInParentheses: false
9494
SpacesInSquareBrackets: false
95-
Standard: Cpp11
95+
Standard: c++20
9696
TabWidth: 8
9797
UseTab: Never
98-

.clang-tidy

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
---
2-
Checks: '*,-fuchsia-*,-google-*,-zircon-*,-abseil-*,-modernize-use-trailing-return-type,-llvm*'
3-
WarningsAsErrors: '*'
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+
"
417
HeaderFilterRegex: ''
518
FormatStyle: none
6-
7-

CMakeLists.txt

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,90 @@
1-
cmake_minimum_required(VERSION 3.15)
1+
CMAKE_MINIMUM_REQUIRED(VERSION 3.15)
22

33
# Set the project name to your project name, my project isn't very descriptive
4-
project(myproject
4+
PROJECT(myproject
55
LANGUAGES CXX
66
VERSION 0.0.1)
77

8-
include(cmake/StandardProjectSettings.cmake)
9-
include(cmake/PreventInSourceBuilds.cmake)
10-
include(cmake/CodeFormat.cmake)
8+
INCLUDE(cmake/StandardProjectSettings.cmake)
9+
INCLUDE(cmake/PreventInSourceBuilds.cmake)
10+
INCLUDE(cmake/CodeFormat.cmake)
1111

12-
execute_process(
12+
EXECUTE_PROCESS(
1313
COMMAND git log -1 --format=%h
1414
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
1515
OUTPUT_VARIABLE GIT_HASH
1616
OUTPUT_STRIP_TRAILING_WHITESPACE
1717
)
1818

19-
configure_file("templates/version.hpp.in" "${CMAKE_BINARY_DIR}/generated/include/version.hpp" ESCAPE_QUOTES)
19+
CONFIGURE_FILE("templates/version.hpp.in" "${CMAKE_BINARY_DIR}/generated/include/version.hpp" ESCAPE_QUOTES)
2020

2121
# Link this 'library' to set the c++ standard / compile-time options requested
22-
add_library(project_options INTERFACE)
23-
target_compile_features(project_options INTERFACE cxx_std_17)
22+
ADD_LIBRARY(project_options INTERFACE)
23+
TARGET_COMPILE_FEATURES(project_options INTERFACE cxx_std_17)
2424

25-
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
26-
option(ENABLE_BUILD_WITH_TIME_TRACE "Enable -ftime-trace to generate time tracing .json files on clang" OFF)
27-
if(ENABLE_BUILD_WITH_TIME_TRACE)
28-
target_compile_options(project_options INTERFACE -ftime-trace)
29-
endif()
30-
endif()
25+
IF(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
26+
OPTION(ENABLE_BUILD_WITH_TIME_TRACE "Enable -ftime-trace to generate time tracing .json files on clang" OFF)
27+
IF(ENABLE_BUILD_WITH_TIME_TRACE)
28+
TARGET_COMPILE_OPTIONS(project_options INTERFACE -ftime-trace)
29+
ENDIF()
30+
ENDIF()
3131

3232
# Link this 'library' to use the warnings specified in CompilerWarnings.cmake
33-
add_library(project_warnings INTERFACE)
33+
ADD_LIBRARY(project_warnings INTERFACE)
3434

3535
# enable cache system
36-
include(cmake/Cache.cmake)
36+
INCLUDE(cmake/Cache.cmake)
3737

3838
# standard compiler warnings
39-
include(cmake/CompilerWarnings.cmake)
40-
set_project_warnings(project_warnings)
39+
INCLUDE(cmake/CompilerWarnings.cmake)
40+
SET_PROJECT_WARNINGS(project_warnings)
4141

4242
# sanitizer options if supported by compiler
43-
include(cmake/Sanitizers.cmake)
44-
enable_sanitizers(project_options)
43+
INCLUDE(cmake/Sanitizers.cmake)
44+
ENABLE_SANITIZERS(project_options)
4545

4646
# enable doxygen
47-
include(cmake/Doxygen.cmake)
48-
enable_doxygen()
47+
INCLUDE(cmake/Doxygen.cmake)
48+
ENABLE_DOXYGEN()
4949

5050
# allow for static analysis options
51-
include(cmake/StaticAnalyzers.cmake)
51+
INCLUDE(cmake/StaticAnalyzers.cmake)
5252

53-
option(BUILD_SHARED_LIBS "Enable compilation of shared libraries" OFF)
54-
option(ENABLE_TESTING "Enable Test Builds" ON)
55-
option(ENABLE_FUZZING "Enable Fuzzing Builds" OFF)
53+
OPTION(BUILD_SHARED_LIBS "Enable compilation of shared libraries" OFF)
54+
OPTION(ENABLE_TESTING "Enable Test Builds" ON)
55+
OPTION(ENABLE_FUZZING "Enable Fuzzing Builds" OFF)
5656

5757
# Very basic PCH example
58-
option(ENABLE_PCH "Enable Precompiled Headers" OFF)
59-
if(ENABLE_PCH)
60-
# This sets a global PCH parameter, each project will build its own PCH, which is a good idea if any #define's change
61-
#
62-
# consider breaking this out per project as necessary
63-
target_precompile_headers(
64-
project_options
65-
INTERFACE
66-
<vector>
67-
<string>
68-
<map>
69-
<utility>)
70-
endif()
58+
OPTION(ENABLE_PCH "Enable Precompiled Headers" OFF)
59+
IF(ENABLE_PCH)
60+
# This sets a global PCH parameter, each project will build its own PCH, which is a good idea if any #define's change
61+
#
62+
# consider breaking this out per project as necessary
63+
TARGET_PRECOMPILE_HEADERS(
64+
project_options
65+
INTERFACE
66+
<vector>
67+
<string>
68+
<map>
69+
<utility>)
70+
ENDIF()
7171

7272
# Set up some extra Conan dependencies based on our needs before loading Conan
73-
set(CONAN_EXTRA_REQUIRES "")
74-
set(CONAN_EXTRA_OPTIONS "")
73+
SET(CONAN_EXTRA_REQUIRES "")
74+
SET(CONAN_EXTRA_OPTIONS "")
7575

76-
include(cmake/Conan.cmake)
77-
run_conan()
76+
INCLUDE(cmake/Conan.cmake)
77+
RUN_CONAN()
7878

79-
if(ENABLE_TESTING)
80-
enable_testing()
81-
message("Building Tests. Be sure to check out test/constexpr_tests for constexpr testing")
82-
add_subdirectory(test)
83-
endif()
79+
IF(ENABLE_TESTING)
80+
ENABLE_TESTING()
81+
MESSAGE("Building Tests. Be sure to check out test/constexpr_tests for constexpr testing")
82+
ADD_SUBDIRECTORY(test)
83+
ENDIF()
8484

85-
if(ENABLE_FUZZING)
86-
message("Building Fuzz Tests, using fuzzing sanitizer https://www.llvm.org/docs/LibFuzzer.html")
87-
add_subdirectory(fuzz_test)
88-
endif()
89-
90-
add_subdirectory(src)
85+
IF(ENABLE_FUZZING)
86+
MESSAGE("Building Fuzz Tests, using fuzzing sanitizer https://www.llvm.org/docs/LibFuzzer.html")
87+
ADD_SUBDIRECTORY(fuzz_test)
88+
ENDIF()
9189

90+
ADD_SUBDIRECTORY(src)

fuzz_test/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# A fuzz test runs until it finds an error. This particular one is going to rely on libFuzzer.
22
#
33

4-
add_executable(fuzz_tester fuzz_tester.cpp)
5-
target_link_libraries(
6-
fuzz_tester
7-
PRIVATE project_options
8-
project_warnings
9-
CONAN_PKG::fmt
10-
-coverage
11-
-fsanitize=fuzzer,undefined,address)
12-
target_compile_options(fuzz_tester PRIVATE -fsanitize=fuzzer,undefined,address)
4+
ADD_EXECUTABLE(fuzz_tester fuzz_tester.cpp)
5+
TARGET_LINK_LIBRARIES(
6+
fuzz_tester
7+
PRIVATE project_options
8+
project_warnings
9+
CONAN_PKG::fmt
10+
-coverage
11+
-fsanitize=fuzzer,undefined,address)
12+
TARGET_COMPILE_OPTIONS(fuzz_tester PRIVATE -fsanitize=fuzzer,undefined,address)
1313

1414
# Allow short runs during automated testing to see if something new breaks
15-
set(FUZZ_RUNTIME
15+
SET(FUZZ_RUNTIME
1616
10
1717
CACHE STRING "Number of seconds to run fuzz tests during ctest run") # Default of 10 seconds
1818

19-
add_test(NAME fuzz_tester_run COMMAND fuzz_tester -max_total_time=${FUZZ_RUNTIME})
19+
ADD_TEST(NAME fuzz_tester_run COMMAND fuzz_tester -max_total_time=${FUZZ_RUNTIME})

fuzz_test/fuzz_tester.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1+
#include <fmt/format.h>
12
#include <iterator>
23
#include <utility>
3-
#include <fmt/format.h>
44

55
[[nodiscard]] auto sum_values(const uint8_t *Data, size_t Size)
66
{
7-
constexpr auto scale = 1000;
7+
constexpr auto scale = 1000;
88

9-
int value = 0;
10-
for (std::size_t offset = 0; offset < Size; ++offset) {
11-
value += static_cast<int>(*std::next(Data, static_cast<long>(offset))) * scale;
12-
}
13-
return value;
9+
int value = 0;
10+
for (std::size_t offset = 0; offset < Size; ++offset) { value += static_cast<int>(*std::next(Data, static_cast<long>(offset))) * scale; }
11+
return value;
1412
}
1513

1614
// Fuzzer that attempts to invoke undefined behavior for signed integer overflow
1715
// cppcheck-suppress unusedFunction symbolName=LLVMFuzzerTestOneInput
1816
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
1917
{
20-
fmt::print("Value sum: {}, len{}\n", sum_values(Data,Size), Size);
21-
return 0;
18+
fmt::print("Value sum: {}, len{}\n", sum_values(Data, Size), Size);
19+
return 0;
2220
}

src/boost.beast/data.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ struct person
88
{
99
std::string name;
1010
std::string address;
11-
int age = {0};
12-
int id = {0};
11+
int age = { 0 };
12+
int id = { 0 };
1313
};
1414

1515
inline void to_json(nlohmann::json &j, const person &p) { j = nlohmann::json{ { "name", p.name }, { "address", p.address }, { "age", p.age }, { "id", p.id } }; }

src/boost.beast/error_handling.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
2+
#include <boost/asio/dispatch.hpp>
3+
#include <boost/asio/strand.hpp>
24
#include <boost/beast/core.hpp>
35
#include <boost/beast/http.hpp>
46
#include <boost/beast/version.hpp>
5-
#include <boost/asio/dispatch.hpp>
6-
#include <boost/asio/strand.hpp>
77
#include <fmt/format.h>
88

99
// from <boost/beast.hpp>

src/boost.beast/listener.h

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
2-
#include "error_handling.h"
32
#include "data.h"
3+
#include "error_handling.h"
44
#include "session.h"
55

66
// Accepts incoming connections and launches the sessions
@@ -13,32 +13,28 @@ class Listener : public std::enable_shared_from_this<Listener>
1313

1414
// Open the acceptor
1515
m_acceptor.open(endpoint.protocol(), ec);
16-
if (ec)
17-
{
16+
if (ec) {
1817
fail(ec, "open");
1918
return;
2019
}
2120

2221
// Allow address reuse
2322
m_acceptor.set_option(asio::socket_base::reuse_address(true), ec);
24-
if (ec)
25-
{
23+
if (ec) {
2624
fail(ec, "set_option");
2725
return;
2826
}
2927

3028
// Bind to the server address
3129
m_acceptor.bind(endpoint, ec);
32-
if (ec)
33-
{
30+
if (ec) {
3431
fail(ec, "bind");
3532
return;
3633
}
3734

3835
// Start listening for connections
3936
m_acceptor.listen(asio::socket_base::max_listen_connections, ec);
40-
if (ec)
41-
{
37+
if (ec) {
4238
fail(ec, "listen");
4339
return;
4440
}
@@ -56,12 +52,9 @@ class Listener : public std::enable_shared_from_this<Listener>
5652

5753
void onAccept(beast::error_code ec, tcp::socket socket)
5854
{
59-
if (ec)
60-
{
55+
if (ec) {
6156
fail(ec, "accept");
62-
}
63-
else
64-
{
57+
} else {
6558
// Create the session and run it
6659
std::make_shared<Session>(std::move(socket), m_persons)->run();
6760
}

0 commit comments

Comments
 (0)