Skip to content

Commit

Permalink
Bump C++ standard from C++17 to C++20.
Browse files Browse the repository at this point in the history
* Use a more CMake-like way to set the C++ standard.

* Various IWYU fixes.

* clang-tidy fix to use std::ranges!

* We need to adapt our code a tiny bit to avoid using an operator<< which
  got deleted in C++20, see:

    https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1423r3.html#option7

* Kicked out a few old compilers from our home-grown auto-detection which
  are definitely not usable anymore.

Change-Id: I66258c961de3b8c9fd4c04a8408abb5f8eee0db2
  • Loading branch information
spt29 committed Aug 18, 2023
1 parent ee5939a commit ce95ecb
Show file tree
Hide file tree
Showing 30 changed files with 72 additions and 53 deletions.
10 changes: 7 additions & 3 deletions packages/livestatus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
cmake_minimum_required(VERSION 3.24)

set(root_repo_dir ${CMAKE_CURRENT_SOURCE_DIR}/../..)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(PLANTUTML_VERSION 1.2022.13)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_COMPILER g++-13) # TODO: replace with more intelligent approach
set(root_repo_dir ${CMAKE_CURRENT_SOURCE_DIR}/../..)

add_compile_options(
-Wall
-Wextra
Expand All @@ -12,7 +18,6 @@ add_compile_options(
-DASIO_NO_DEPRECATED
-fPIC
-gdwarf-4
-std=c++17
-O3)

project(
Expand All @@ -21,6 +26,5 @@ project(
DESCRIPTION "Livestatus library"
LANGUAGES CXX)

# SUB-DIRS:
add_subdirectory(src)
add_subdirectory(test)
2 changes: 1 addition & 1 deletion packages/livestatus/doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ CLANG_ADD_INC_PATHS = YES
# specified with INPUT and INCLUDE_PATH.
# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES.

CLANG_OPTIONS = -std=c++17 \
CLANG_OPTIONS = -std=c++20 \
-Iinclude \
-Ibuild/_deps/asio-omd-src/include \
-Ibuild/_deps/re2-src \
Expand Down
1 change: 1 addition & 0 deletions packages/livestatus/include/livestatus/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define Renderer_h

#include <chrono>
#include <compare>
#include <cstdint>
#include <iomanip>
#include <iosfwd>
Expand Down
1 change: 1 addition & 0 deletions packages/livestatus/src/AttributeListColumn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "livestatus/AttributeListColumn.h"

#include <algorithm>
#include <bitset>
#include <cctype>
#include <map>
Expand Down
1 change: 1 addition & 0 deletions packages/livestatus/src/Column.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "livestatus/Column.h"

#include <algorithm>
#include <utility>

Column::Column(std::string name, std::string description, ColumnOffsets offsets)
Expand Down
1 change: 1 addition & 0 deletions packages/livestatus/src/DictFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "livestatus/DictFilter.h"

#include <algorithm>
#include <compare>
#include <cstddef>
#include <tuple>
#include <unordered_map>
Expand Down
2 changes: 2 additions & 0 deletions packages/livestatus/src/InputBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

#include <unistd.h>

#include <algorithm>
#include <cctype>
#include <cerrno>
#include <compare>
#include <cstring>
#include <ostream>
#include <string_view>
Expand Down
7 changes: 5 additions & 2 deletions packages/livestatus/src/LogCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

#include "livestatus/LogCache.h"

#include <algorithm>
#include <compare>
#include <iterator>
#include <ranges>
#include <system_error>

#include "livestatus/ICore.h"
Expand Down Expand Up @@ -79,8 +82,8 @@ LogCache::pathsSince(std::chrono::system_clock::time_point since) {
update();
std::vector<std::filesystem::path> paths;
bool horizon_reached{false};
for (auto it = _logfiles.crbegin(); it != _logfiles.crend(); ++it) {
const auto &[unused, log_file] = *it;
for (const auto &[unused, log_file] :
std::ranges::reverse_view(_logfiles)) {
if (horizon_reached) {
return {paths, log_file->path()};
}
Expand Down
1 change: 1 addition & 0 deletions packages/livestatus/src/Logfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <algorithm>
#include <cerrno>
#include <compare>
#include <sstream>
#include <stdexcept>
#include <vector>
Expand Down
1 change: 1 addition & 0 deletions packages/livestatus/src/POSIXUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <sys/socket.h>
#include <unistd.h>

#include <compare>
#include <ratio>
#include <thread>

Expand Down
1 change: 1 addition & 0 deletions packages/livestatus/src/ParsedQuery.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <algorithm>
#include <cctype>
#include <cmath>
#include <compare>
#include <cstdint>
#include <cstdlib>
#include <map>
Expand Down
2 changes: 2 additions & 0 deletions packages/livestatus/src/Query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

#include "livestatus/Query.h"

#include <algorithm>
#include <cassert>
#include <compare>
#include <sstream>
#include <utility>

Expand Down
11 changes: 6 additions & 5 deletions packages/livestatus/src/Renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ void Renderer::output(double value) {
void Renderer::output(const RowFragment &value) { _os << value._str; }

void Renderer::outputUnicodeChar(char32_t value) {
if (value < 0x10000U) {
outputHex('u', 4, value);
const uint_least32_t number{value};
if (number < 0x10000U) {
outputHex('u', 4, number);
} else if (useSurrogatePairs()) {
outputHex('u', 4, 0xd800U | (((value - 0x10000U) >> 10) & 0x3ffU));
outputHex('u', 4, 0xdc00U | ((value - 0x10000U) & 0x3ffU));
outputHex('u', 4, 0xd800U | (((number - 0x10000U) >> 10) & 0x3ffU));
outputHex('u', 4, 0xdc00U | ((number - 0x10000U) & 0x3ffU));
} else {
outputHex('U', 8, value);
outputHex('U', 8, number);
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/livestatus/src/StringFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "livestatus/StringFilter.h"

#include <compare>
#include <utility>

#include "livestatus/RegExp.h"
Expand Down
1 change: 1 addition & 0 deletions packages/livestatus/src/TableHostGroups.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// source code package.
#include "livestatus/TableHostGroups.h"

#include <algorithm>
#include <memory>
#include <vector>

Expand Down
1 change: 1 addition & 0 deletions packages/livestatus/src/TableHosts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "livestatus/TableHosts.h"

#include <algorithm>
#include <chrono>
#include <cstdint>
#include <filesystem>
Expand Down
1 change: 1 addition & 0 deletions packages/livestatus/src/TableServiceGroups.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "livestatus/TableServiceGroups.h"

#include <algorithm>
#include <memory>
#include <vector>

Expand Down
1 change: 1 addition & 0 deletions packages/livestatus/src/TableServices.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "livestatus/TableServices.h"

#include <algorithm>
#include <chrono>
#include <cstdint>
#include <filesystem>
Expand Down
1 change: 1 addition & 0 deletions packages/livestatus/src/TableStateHistory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "livestatus/TableStateHistory.h"

#include <compare>
#include <cstddef>
#include <optional>
#include <ratio>
Expand Down
1 change: 1 addition & 0 deletions packages/livestatus/src/TrialManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <endian.h>

#include <compare>
#include <cstdint>
#include <istream>
#include <ratio>
Expand Down
1 change: 1 addition & 0 deletions packages/livestatus/src/global_counters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "livestatus/global_counters.h"

#include <chrono>
#include <compare>
#include <mutex>
#include <optional>
#include <ratio>
Expand Down
1 change: 1 addition & 0 deletions packages/livestatus/test/test_LogEntry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// terms and conditions defined in the file COPYING, which is part of this
// source code package.

#include <algorithm>
#include <chrono>
#include <ctime>
#include <stdexcept>
Expand Down
1 change: 1 addition & 0 deletions packages/livestatus/test/test_Metric.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// source code package.

#include <algorithm>
#include <compare>
#include <filesystem>
#include <fstream>
#include <iterator>
Expand Down
16 changes: 10 additions & 6 deletions packages/neb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
cmake_minimum_required(VERSION 3.24)

set(root_repo_dir ${CMAKE_CURRENT_SOURCE_DIR}/../..)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMK_VERSION 2.3.0)
set(PLANTUTML_VERSION 1.2022.13)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_COMPILER g++-13) # TODO: replace with more intelligent approach
set(root_repo_dir ${CMAKE_CURRENT_SOURCE_DIR}/../..)

set(CMK_VERSION 2.3.0)
string(REGEX REPLACE "([0-9]+)\.([0-9]+)\.([0-9]+).*" "\\1.\\2.\\3"
MANGLED_VERSION ${CMK_VERSION})

add_compile_options(
-Wall
-Wextra
Expand All @@ -14,17 +22,13 @@ add_compile_options(
-DASIO_NO_DEPRECATED
-fPIC
-gdwarf-4
-std=c++17
-O3)

string(REGEX REPLACE "([0-9]+)\.([0-9]+)\.([0-9]+).*" "\\1.\\2.\\3"
MANGLED_VERSION ${CMK_VERSION})
project(
neb
VERSION ${MANGLED_VERSION}
DESCRIPTION "Livestatus NEB"
LANGUAGES CXX)

# SUB-DIRS:
add_subdirectory(src)
add_subdirectory(test)
2 changes: 1 addition & 1 deletion packages/neb/doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ CLANG_ADD_INC_PATHS = YES
# specified with INPUT and INCLUDE_PATH.
# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES.

CLANG_OPTIONS = -std=c++17 \
CLANG_OPTIONS = -std=c++20 \
-Iinclude \
-Ithird_party/include \
-Ibuild/_deps/asio-omd-src/include \
Expand Down
1 change: 1 addition & 0 deletions packages/neb/src/TimeperiodsCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "neb/TimeperiodsCache.h"

#include <compare>
#include <ratio>
#include <utility>

Expand Down
1 change: 1 addition & 0 deletions packages/neb/src/module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <atomic>
#include <cerrno>
#include <chrono>
#include <compare>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
Expand Down
1 change: 1 addition & 0 deletions packages/neb/test/test_utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "test_utilities.h"

#include <algorithm>
#include <string>
#include <unordered_map>
#include <utility>
Expand Down
9 changes: 6 additions & 3 deletions packages/unixcat/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
cmake_minimum_required(VERSION 3.24)

set(root_repo_dir ${CMAKE_CURRENT_SOURCE_DIR}/../..)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(PLANTUTML_VERSION 1.2022.13)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_COMPILER g++-13) # TODO: replace with more intelligent approach
set(root_repo_dir ${CMAKE_CURRENT_SOURCE_DIR}/../..)

add_compile_options(
-Wall
-Wextra
-Werror
-DHAVE_RE2
-fPIC
-gdwarf-4
-std=c++17
-O3)

project(
Expand All @@ -20,6 +24,5 @@ project(
DESCRIPTION "unixcat"
LANGUAGES CXX)

# SUB-DIRS:
add_subdirectory(src)
add_subdirectory(test)
Loading

0 comments on commit ce95ecb

Please sign in to comment.