RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1180035 - regex: sub_match does not form half open interval
Summary: regex: sub_match does not form half open interval
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: gcc
Version: 7.1
Hardware: All
OS: Unspecified
unspecified
medium
Target Milestone: rc
: ---
Assignee: Jakub Jelinek
QA Contact: qe-baseos-tools-bugs
URL:
Whiteboard:
: 1764617 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-01-08 07:21 UTC by Miroslav Franc
Modified: 2019-10-23 13:32 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-01-08 08:07:49 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Miroslav Franc 2015-01-08 07:21:59 UTC
Description of problem:

When extracting regex submatches with regex_match function I would expect the first iterator of every sub_match to point to the start of the matched sequence and the second one to point one element past the end.  This does not seem to be the case.  The iterators form open instead of half open interval.


--- regex.cc ---
#include <cstddef>
#include <regex>
#include <string>
#include <iostream>

using namespace std;

int main ()
{ 
  const regex r ("xxx(y*)xxx(y*)xxx(y*)xxx");
  string s;
  smatch m;

  getline (cin, s);

  if (regex_match (s, m, r))
    { 
      for (unsigned int i = 1; i < m.size (); ++i)
        { 
          const size_t b = m[i].first - s.begin ();
          const size_t e = m[i].second - s.begin ();
          string markers (s.size (), ' ');
          markers[b] = '^'; markers[e] = '^';

          cout << "submatch: " << m[i] << '\n';
          cout << "length: " << m[i].length () << '\n';
          cout << "interval: [ " << b << ", " << e << " )\n";
          cout << "first iterator points to: " << *m[i].first << '\n';
          cout << s << '\n';
          cout << markers << endl;
        }
    }
}
--- ---  --- ---


Version-Release number of selected component (if applicable):
libstdc++-4.8.3-9.el7


Steps to Reproduce:
1. g++ -O2 -std=c++11 -g    regex.cc   -o regex
2. ./regex <<<xxxyyyxxxyxxxxxx


Actual results:
submatch: xyyy
length: 4
interval: [ 2, 6 )
first iterator points to: x
xxxyyyxxxyxxxxxx
  ^   ^
submatch: xy
length: 2
interval: [ 8, 10 )
first iterator points to: x
xxxyyyxxxyxxxxxx
        ^ ^
submatch: x
length: 1
interval: [ 12, 13 )
first iterator points to: x
xxxyyyxxxyxxxxxx
            ^^


Expected results:
submatch: yyy
length: 3
interval: [ 3, 6 )
first iterator points to: y
xxxyyyxxxyxxxxxx
   ^  ^         
submatch: y
length: 1
interval: [ 9, 10 )
first iterator points to: y
xxxyyyxxxyxxxxxx
         ^^     
submatch: 
length: 0
interval: [ 13, 13 )
first iterator points to: x
xxxyyyxxxyxxxxxx
             ^  


Additional info:

Comment 1 Jakub Jelinek 2015-01-08 07:50:32 UTC
Are you talking here really about the system libstdc++?  Because in GCC 4.8-RH <regex> is not implemented, there are some headers and perhaps some things compile, but that is about it (at least that is my understanding):
https://gcc.gnu.org/onlinedocs/gcc-4.8.4/libstdc++/manual/manual/status.html
says:
28 	Regular expressions
28.1	General	N	 
28.2	Definitions	N	 
28.3	Requirements	N	 
28.4	Header <regex> synopsis	N	 
28.5	Namespace std::regex_constants	Y	 
28.6	Class regex_error	Y	 
28.7	Class template regex_traits	Partial	 
28.8	Class template basic_regex	Partial	 
28.9	Class template sub_match	Partial	 
28.10	Class template match_results	Partial	 
28.11	Regular expression algorithms	N	 
28.12	Regular expression Iterators	N	 
28.13	Modified ECMAScript regular expression grammar	N	 

For usable <regex> you need GCC 4.9 or later, which has:
28 	Regular expressions
28.1	General	Y	 
28.2	Definitions	Y	 
28.3	Requirements	Y	 
28.4	Header <regex> synopsis	Y	 
28.5	Namespace std::regex_constants	Y	 
28.6	Class regex_error	Y	 
28.7	Class template regex_traits	Partial	transform_primary is not correctly implemented	 
28.8	Class template basic_regex	Y	 
28.9	Class template sub_match	Y	 
28.10	Class template match_results	Y	 
28.11	Regular expression algorithms	Y	 
28.12	Regular expression Iterators	Y	 
28.13	Modified ECMAScript regular expression grammar	Y

Comment 3 Florian Weimer 2019-10-23 13:31:20 UTC
*** Bug 1764617 has been marked as a duplicate of this bug. ***


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