Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: Require GCC 10.1 for std::in_range<>() #1204

Merged

Conversation

ppisar
Copy link
Contributor

@ppisar ppisar commented Jan 25, 2024

A GCC 9.2 user reported this failure:

In file included from /home/rpm/rpmbuild/BUILD/common/utils/string.cpp:21:
/home/rpm/rpmbuild/BUILD/common/utils/string.hpp: In function 'std::string libdnf5::utils::string::format_epoch(T)':
/home/rpm/rpmbuild/BUILD/common/utils/string.hpp:115:14: error: 'in_range' is not a member of 'std'
  115 |     if (std::in_range<time_t>(epoch_num)) {
  |              ^~~~~~~~

The cause is that std::in_range<>() is a C++20 feature added to GCC in version 10.1.

This patch sets the minimal version in dnf5.spec.

Originally, I also wanted to add a check into a build script to fail early. std::in_range<>() is supported if the compiler defines __cpp_lib_integer_comparison_functions >= 202002L feature test macro.

However, checking for it in CMake is very difficult: target_compile_features() does not recognize this specific feature. check_cxx_symbol_exists() is unable to retrieve the macro value. CheckSourceCompiles() requires CMake 3.19 (a year after GCC 10.1).

So I scratched out the idea of adding a check into the build script.

Fixes: #1167

A GCC 9.2 user reported this failure:

    In file included from /home/rpm/rpmbuild/BUILD/common/utils/string.cpp:21:
    /home/rpm/rpmbuild/BUILD/common/utils/string.hpp: In function 'std::string libdnf5::utils::string::format_epoch(T)':
    /home/rpm/rpmbuild/BUILD/common/utils/string.hpp:115:14: error: 'in_range' is not a member of 'std'
      115 |     if (std::in_range<time_t>(epoch_num)) {
	  |              ^~~~~~~~

The cause is that std::in_range<>() is a C++20 feature added to GCC
in version 10.1.

This patch sets the minimal version in dnf5.spec.

Originally, I also wanted to add a check into a build script to fail
early. std::in_range<>() is supported if the compiler defines
__cpp_lib_integer_comparison_functions >= 202002L feature test macro.

However, checking for it in CMake is very difficult:
target_compile_features() does not recognize this specific feature.
check_cxx_symbol_exists() is unable to retrieve the macro value.
CheckSourceCompiles() requires CMake 3.19 (a year after GCC 10.1).

So I scratched out the idea of adding a check into the build script.

Fixes: rpm-software-management#1167
Copy link
Member

@jan-kolarik jan-kolarik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jan-kolarik jan-kolarik added this pull request to the merge queue Jan 26, 2024
Merged via the queue into rpm-software-management:main with commit e5786a8 Jan 26, 2024
5 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FTBFS with gcc 9.x: 'in_range' is not a member of 'std'
2 participants