Use of C++17/20 features/extensions
The src/zimwriterfs/zimcreatorfs.cpp file uses designated initializers, which is a c++20 feature. It currently works by relying on compiler c++20-extensions with the c++ standard set to c++17 in meson.build.
Are there any dependency blockers for just changing the c++ standard version to c++20? If there aren't any blockers I can put in a PR.
We want to keep things compiling on older compilers. The strategy is to allow c++ 14 features but not higher.
It would be helpful if we could figure out which minimum compiler version we specifically want to target. The codebase already uses some >= C++17 features, so those sections would need a downgrade to comply with the intended target of C++14. Is the Repology page accurate?
We have to compile on cpp14 compilers, therefore we should not use moderner breaking forms.
Do you have some kind of detailed report showing that the code is not cpp14 compliant anymore?
Hi Kelson,
Thank you for the quick reply. Here are the ones that stood out to me.
https://github.com/openzim/zim-tools/blob/a65cb01f63d391f6684e823f5d6c3dcef3ce7fda/meson.build#L4
4: default_options : ['c_std=c11', 'cpp_std=c++17', 'werror=true', 'warning_level=1'])
^^^^^^^^^^^^^^^^
https://github.com/openzim/zim-tools/blob/a65cb01f63d391f6684e823f5d6c3dcef3ce7fda/src/zimwriterfs/zimcreatorfs.cpp#L45
45: Redirect redirect = {
.path= matches[1].str(), // designated initializers are a c++20 feature
.title = matches[2].str(), // and only work prior to that using a compiler extension
.target = matches[3].str() // If you change warning_level=3 in meson.build
}; // it will show -Werror=c++20-extensions
I also found this https://github.com/openzim/zim-tools/wiki/Repology, but I am not sure if that is up to date. I am just trying to figure out which specific compiler versions are the bare minimum we want to support so it can be documented (and so I can install those versions in a container so I can test locally). Just picking out of that repology list and a cursory internet search:
Debian 10 uses GCC 10 Alpine Linux 3.16 uses LLVM 13 Ubuntu 22.04 uses GCC 11.2 Raspbian Oldstable uses GCC 8
As a bit of a followup:
libzim targets c++17. https://github.com/openzim/libzim/blob/40bfe6470490fb52b0a44a9fdab8ddbaad37b181/meson.build#L4
xapian-core targets c++11 https://github.com/openzim/xapian-meson/blob/d3efba172e832ce9b0860996576e96eef7850d83/xapian-core/meson.build#L2
kiwix-tools targets c++17 https://github.com/kiwix/kiwix-tools/blob/e65354a486376445d809f4a1dd7e3394b5e933ba/meson.build#L4
libkiwix targets c++17 https://github.com/kiwix/libkiwix/blob/6c37e2827e6ccf0497d20b5cfe1696df6481c4ed/meson.build#L4
The oldest compiler I found in the Repology link https://github.com/openzim/zim-tools/wiki/Repology was GCC 8 with Raspbian Oldstable.
Checking the support pages, the c++17 support for GCC 8 is complete, and a majority of the c++17 standard library features are supported as well. The only standard library features which are not supported were pmr, parallel algorithms, and hardware_inference_size, which are generally of more niche use cases anyway. Most of c++17 is supported back in GCC 7. https://en.cppreference.com/w/cpp/compiler_support/17 https://en.cppreference.com/w/cpp/compiler_support/17#C.2B.2B17_library_features
It looks like C++17 target was added in this repository August 30, 2023 by @mgautierfr:
https://github.com/openzim/zim-tools/commit/297e672826d599076cbe3ec31337bbefa3d737e4
I speak under the control of @mgautierfr and @veloman-yunkan but the agreement between us was "you can compile and respect the c++17 norm but not use c++17 new features". But this is already at least 18months old, maybe we should reasses this? @veloman-yunkan @mgautierfr What concretly would speak against using C++17 new features?