Bug 77469 - std::regex x("[b\\-a]") throws with message "Invalid range in bracket expression."
Summary: std::regex x("[b\\-a]") throws with message "Invalid range in bracket express...
Status: RESOLVED DUPLICATE of bug 77356
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 6.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-04 00:50 UTC by alban_sf
Modified: 2016-09-06 09:33 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Test program with the bug (208 bytes, text/x-csrc)
2016-09-04 00:52 UTC, alban_sf
Details
config.log from building gcc 6.2.0 (6.50 KB, text/plain)
2016-09-04 00:54 UTC, alban_sf
Details
Preprocessed file generated by -save-temps (204.97 KB, application/gzipped-tar)
2016-09-04 01:01 UTC, alban_sf
Details

Note You need to log in before you can comment on or make changes to this bug.
Description alban_sf 2016-09-04 00:50:04 UTC
Hello,

The std::regex constructor throws when passed "[b\\-a]".  The message is "Invalid range in bracket expression.".

I understand that this is a valid regular expression that specifies a character class consisting of a literal "b", a literal "-", and a literal "a".

g++ version:  6.2.0.

System:  Ubuntu 12.04.2 LTS.

Output of 'uname -a':  Linux zeus 3.2.0-68-generic #102-Ubuntu SMP Tue Aug 12 22:02:15 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

gcc configuration options:  ./configure --disable-multilib

Build command line:  g++ testRegex.cc -o testRegex -std=c++11 -Wall -Wextra -fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations -fsanitize=undefined

There are no compiler messages.

This behaviour does not occur with gcc Ubuntu 4.9.2-0ubuntu1~14.04.

This behaviour also occurs with MinGW-W64 5.3.0 and 6.1.0.

Thank you,
Alban
Comment 1 alban_sf 2016-09-04 00:52:41 UTC
Created attachment 39543 [details]
Test program with the bug

Build the program:

  g++ testRegex.cc -o testRegex -std=c++11

Run:

  ./testRegex

Output:

  Trying:  [b\-a]
  Exception:  Invalid range in bracket expression.
Comment 2 alban_sf 2016-09-04 00:54:21 UTC
Created attachment 39544 [details]
config.log from building gcc 6.2.0
Comment 3 alban_sf 2016-09-04 01:01:15 UTC
Created attachment 39545 [details]
Preprocessed file generated by -save-temps
Comment 4 Andreas Schwab 2016-09-04 06:02:52 UTC
\ is not special inside bracket expressions, [b\-a] means b and the range between \ and a.  If you want to include a - in a bracket expression, put it first or last.
Comment 5 Tim Shen 2016-09-04 20:13:57 UTC

*** This bug has been marked as a duplicate of bug 77356 ***
Comment 6 Jonathan Wakely 2016-09-06 09:33:54 UTC
(In reply to Andreas Schwab from comment #4)
> \ is not special inside bracket expressions, [b\-a] means b and the range
> between \ and a.  If you want to include a - in a bracket expression, put it
> first or last.

That's true for POSIX BREs and EREs, but for ECMAScript escaping the dash should work (and does on trunk).