Skip to content

Commit

Permalink
Upgrade the minimum compiler C++17
Browse files Browse the repository at this point in the history
See discussion on #106

Full C++17 support came in gcc 8 (although most of it was present in gcc
7 already. In terms of our likely target platforms already ship that:

* Debian oldstable shipped with gcc-10.
* The oldest supported Yocto release is Dunfell, which shipped gcc 9.5

That suggests that getting a C++17 compiler shouldn't be a huge problem
for our downstream.

Why not go further? C++20 support would require gcc 10 or 11, and while
we could go that far it seems like we should be conservative by default.
  • Loading branch information
cajun-rat committed Aug 2, 2024
1 parent f88fb5f commit 1cb0ebf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 35 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ else()
message(WARNING "shellcheck not found, skipping")
endif()

# Use C++11, but without GNU or other extensions
set(CMAKE_CXX_STANDARD 11)
# Use C++17, but without GNU or other extensions
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)

# Export compile_commands.json for clang-tidy
Expand Down
37 changes: 4 additions & 33 deletions src/libaktualizr/utilities/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,39 +172,10 @@ static void curlEasySetoptWrapper(CURL *curl_handle, CURLoption option, T &&...a
}
}

// this is reference implementation of make_unique which is not yet included to C++11
// Aktualizr used to compile on C++11, where std::make_unique wasn't present.
// std_ used to contain an implementation of make_unique, and there are various
// references throughout the codebase. This provides backwards compatbility.
namespace std_ {
template <class T>
struct _Unique_if { // NOLINT(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
using _Single_object = std::unique_ptr<T>; // NOLINT(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
};

template <class T>
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays,bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
struct _Unique_if<T[]> {
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays,bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
using _Unknown_bound = std::unique_ptr<T[]>;
};

template <class T, size_t N>
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays,bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
struct _Unique_if<T[N]> {
using _Known_bound = void; // NOLINT(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
};

template <class T, class... Args>
typename _Unique_if<T>::_Single_object make_unique(Args &&...args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}

template <class T>
typename _Unique_if<T>::_Unknown_bound make_unique(size_t n) {
using U = typename std::remove_extent<T>::type;
return std::unique_ptr<T>(new U[n]());
using std::make_unique;
}

template <class T, class... Args>
typename _Unique_if<T>::_Known_bound make_unique(Args &&...) = delete;
} // namespace std_

#endif // UTILS_H_

0 comments on commit 1cb0ebf

Please sign in to comment.