Opened 5 years ago

Last modified 5 years ago

#13256 new Bugs

regex '([|&])\1?' with backreference fails to compile if regex::nosub flag used

Reported by: Gene Thomas <gene@…> Owned by: John Maddock
Milestone: To Be Determined Component: regex
Version: Boost 1.58.0 Severity: Problem
Keywords: regex nosub Cc: gcc

Description

when compiling a regex with regex::nosubs flag set, a regex with a back reference fails with:

Invalid back reference: specified capturing group does not exist. The error occurred while parsing the regular expression: '([|&])>>>HERE>>>\1?'.

Test program:

#include <boost/regex.hpp> #include <iostream> #include <exception>

using namespace std;

int main(int argc, char argv) {

try {

boost::regex::flag_type flags = boost::regex::ECMAScript; flags |= boost::regex::nosubs; boost::regex theRegex("([|&])
1?", flags); cout << "ok\n"; return 0;

} catch (exception &e) {

cerr << "exception: " << e.what() << "\n"; return 1;

}

} g++ -std=c++11 test-boost-regex-bug.cpp -o test-boost-regex-bug -l boost_regex

Change History (1)

comment:1 by Gene Thomas <gene@…>, 5 years ago

Test program again

#include <boost/regex.hpp>
#include <iostream>
#include <exception>

using namespace std;

int main(int argc, char **argv) {
    
    try {
        boost::regex::flag_type flags = boost::regex::ECMAScript;
        flags |= boost::regex::nosubs;
        boost::regex theRegex("([|&])\\1?", flags);
        cout << "ok\n";
        return 0;
    } catch (exception &e) {
        cerr << "exception: " << e.what() << "\n";
        return 1;
    }
}
Note: See TracTickets for help on using tickets.