[squid-dev] RFC: Switch to C++17

Alex Rousskov rousskov at measurement-factory.com
Sun Dec 4 16:18:17 UTC 2022


Hello,

     I propose that we switch master/v6 from C++11 to C++17: Modern 
environments support C++17 well. We are wasting significant amounts of 
time on emulating such basic C++17 features as std::optional. We are 
writing worse code than we can because we lack access to such basic 
C++14 and C++17 features as

* function return type deduction (auto)
* generic lambdas (auto arguments)
* relaxed constexpr restrictions
* std::make_unique
* std::integer_sequence
* std::quoted
* Nested namespace definitions
* [[fallthrough]], [[maybe_unused]], and [[nodiscard]]
* fold expressions
* auto [a, b] = getTwoReturnValues();
* inline variables
* std::any
* std::variant
* std::byte

If we do not switch now, then we would have to wait about a year for the 
next such opportunity because we should not introduce such a big 
difference between master and the upcoming unstable v6 branch.


C++17 is supported by popular modern compilers and stable distros. Squid 
master branch should target those IMO. Even old environments can install 
the necessary modern compilers (e.g., RHEL5 users can get them via Red 
Hat Developer Toolset).

* GCC v5 supports most C++17 features.
* GCC v8 supports all relevant C++17 features.
* Clang v5 supports nearly all C++17 features.
* Clang v8 supports all relevant C++17 features.

* Ubuntu 20.04 LTS ships with GCC v9 and clang v10.

* https://gcc.gnu.org/projects/cxx-status.html#cxx17
* 
https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2017
* https://clang.llvm.org/cxx_status.html#cxx17
* https://en.cppreference.com/w/cpp/compiler_support/17


Switching to just C++14 would be better than nothing, but it will not 
give us several C++17 features that we already waste serious time on 
emulating/avoiding (e.g., std::optional). We should not switch to C++20 
yet because modern stable compilers still have some C++20 support holes.


I can volunteer the corresponding PR.


Any objections to switching master/v6 to C++17?


Thank you,

Alex.


More information about the squid-dev mailing list