Bug 2010975 - Missing C++2a std::string starts_with(); method on libstdc++
Summary: Missing C++2a std::string starts_with(); method on libstdc++
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: gcc
Version: 8.4
Hardware: x86_64
OS: Linux
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Marek Polacek
QA Contact: qe-baseos-tools-bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-10-05 17:17 UTC by Vinícius Ferrão
Modified: 2023-07-18 14:19 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2021-10-05 17:56:34 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-98908 0 None None None 2021-10-05 17:19:52 UTC

Description Vinícius Ferrão 2021-10-05 17:17:02 UTC
Description of problem:
It seems that starts_with(); method from std::string is missing on EL8.4 even when we use --std=c++2a with gcc (or clang). Both compilers supports C++20 but it seems the implementation is missing from libstdc++.

[root@localhost ~]# g++ --std=c++2a starts_with.c 
starts_with.c: In function 'int main()':
starts_with.c:6:19: error: 'std::__cxx11::string' {aka 'class std::__cxx11::basic_string<char>'} has no member named 'starts_with'
  std::cout << var.starts_with("is") << std::endl;
                   ^~~~~~~~~~~

Version-Release number of selected component (if applicable):
gcc-c++-8.4.1-1.el8.x86_64
clang-devel-11.0.0-1.module+el8.4.0+8598+a071fcd5.x86_64
libstdc++-8.4.1-1.el8.x86_64
libgcc-8.4.1-1.el8.x86_64
clang-tools-extra-11.0.0-1.module+el8.4.0+8598+a071fcd5.x86_64
clang-11.0.0-1.module+el8.4.0+8598+a071fcd5.x86_64
gcc-8.4.1-1.el8.x86_64
clang-libs-11.0.0-1.module+el8.4.0+8598+a071fcd5.x86_64
libstdc++-devel-8.4.1-1.el8.x86_64

How reproducible:
100%

Steps to Reproduce:
1. Create an example program with std::string and use the method starts_with();
2. Fail to compile with bundled gcc and libstdc++

Actual results:
Compiler error during compile phase.

Expected results:
Successful compilation.

Additional info:
std::string starts_with() is defined on C++20: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0457r2.html

It should be supported if we have the option to enable --std=c++2a on compilers.

Example code:
#include <string>
#include <iostream>

int main() {
	std::string var = "this is a test";
	std::cout << var.starts_with("is") << std::endl;

	return 0;
}

Comment 1 Marek Polacek 2021-10-05 17:56:34 UTC
C++20 support in GCC 8 is so early and experimental that I'm not minded to backport any new features there, sorry.

starts_with was added in GCC 9.  On RHEL 8 you can use the GCC Toolset to get a newer compiler than the system one:
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/developing_c_and_cpp_applications_in_rhel_8/gcc-toolset-10_toolsets
which has better C++20 support.

Comment 2 Vinícius Ferrão 2021-10-05 18:04:54 UTC
No problem Marek. I understood, incorrectly, that since gcc allowed --std=c++2a it would support it. I'll default back to --std=c++17.

Thank you.

Comment 3 Marek Polacek 2021-10-13 15:41:34 UTC
Further clarification: C++20 in GCC 10 is still experimental, even though the string::starts_with member is present.


Note You need to log in before you can comment on or make changes to this bug.