Home Dashboard Directory Help
Search

std::regex bug in vs2010 by prog76


Status: 

Closed
 as Fixed Help for as Fixed


1
1
Sign in
to vote
Type: Bug
ID: 642277
Opened: 2/9/2011 8:32:48 PM
Access Restriction: Public
2
Workaround(s)
view
1
User(s) can reproduce this bug

Description

Please chesk steps to reproduce. I'm understand that it is impossible to fix this bug, but may be workaround please?
Details
Sign in to post a comment.
Posted by Microsoft on 2/17/2011 at 7:57 PM
Hi,

Thanks for reporting this bug. We've already fixed it, and the fix will be available in VC11.

First, please note that you can simplify your regex, because parentheses don't need to be escaped within character classes (i.e. square brackets).

Second, because concatenation binds more tightly than alternation, you can remove the second non-capture group in (?:abc|(?:xyz)) and simply use (?:abc|xyz) instead.

Finally, I'd like to point out that the use of "\\)*" in PROPERTIES_CONTENTS looks very suspicious to me, as it can consume zero or more closing parentheses. Unless I'm missing something, exactly one closing parenthesis should be desired here. However, since this doesn't affect your example string, I didn't attempt to modify your regex's semantics here.

Here's a demonstration of the bug in VC10 and the fix in VC11.

C:\Temp>type meow.cpp
#include <stddef.h>
#include <stdio.h>
#include <iostream>
#include <ostream>
#include <regex>
#include <string>
using namespace std;

#define NON_MATCHING_GROUP(X) "(?:" X ")"
#define OPT_NON_MATCHING_GROUP(X) NON_MATCHING_GROUP(X) "?"
#define OPT_SPACE "\\s*"

#ifdef ORIGINAL
    #define NON_BRACKETS "[^\\(\\)]*"
    #define PROPERTIES_CONTENTS NON_MATCHING_GROUP(NON_BRACKETS "|" NON_MATCHING_GROUP( "\\(" NON_BRACKETS "\\)*")) "*"
#elif defined(SIMPLIFIED)
    #define NON_BRACKETS "[^()]*"
    #define PROPERTIES_CONTENTS NON_MATCHING_GROUP(NON_BRACKETS "|" "\\(" NON_BRACKETS "\\)*") "*"
#endif

#define PROPERTIES_DEF "\\((" PROPERTIES_CONTENTS ")\\)"
#define OPTIONAL_PROPERTIES OPT_NON_MATCHING_GROUP(PROPERTIES_DEF)
#define PATTERN "\\w+" OPT_SPACE OPTIONAL_PROPERTIES OPT_SPACE OPTIONAL_PROPERTIES

int main() {
    printf("%02d.%02d.%05d.%02d\n", _MSC_VER / 100, _MSC_VER % 100, _MSC_FULL_VER % 100000, _MSC_BUILD);

    const string s("DATA (123) (345 (678) )");
    const regex r(PATTERN);

    cout << "s: \"" << s << "\"" << endl;
    cout << "r: \"" << PATTERN << "\"" << endl;

    smatch m;

    if (regex_search(s, m, r)) {
        for (size_t i = 0; i < m.size(); ++i) {
            cout << "m[" << i << "]: \"" << m[i] << "\"" << endl;
        }
    } else {
        cout << "FALSE!" << endl;
    }
}

[VC10 RTM]
C:\Temp>cl /EHsc /nologo /W4 /MTd /DORIGINAL meow.cpp && meow
meow.cpp
16.00.30319.01
s: "DATA (123) (345 (678) )"
r: "\w+\s*(?:\(((?:[^\(\)]*|(?:\([^\(\)]*\)*))*)\))?\s*(?:\(((?:[^\(\)]*|(?:\([^\(\)]*\)*))*)\))?"
m[0]: "DATA (123) "
m[1]: "123"
m[2]: ""

C:\Temp>cl /EHsc /nologo /W4 /MTd /DSIMPLIFIED meow.cpp && meow
meow.cpp
16.00.30319.01
s: "DATA (123) (345 (678) )"
r: "\w+\s*(?:\(((?:[^()]*|\([^()]*\)*)*)\))?\s*(?:\(((?:[^()]*|\([^()]*\)*)*)\))?"
m[0]: "DATA (123) "
m[1]: "123"
m[2]: ""

[My current build of VC11]
C:\Temp>cl /EHsc /nologo /W4 /MTd /DORIGINAL meow.cpp && meow
meow.cpp
17.00.40214.00
s: "DATA (123) (345 (678) )"
r: "\w+\s*(?:\(((?:[^\(\)]*|(?:\([^\(\)]*\)*))*)\))?\s*(?:\(((?:[^\(\)]*|(?:\([^\(\)]*\)*))*)\))?"
m[0]: "DATA (123) (345 (678) )"
m[1]: "123"
m[2]: "345 (678) "

C:\Temp>cl /EHsc /nologo /W4 /MTd /DSIMPLIFIED meow.cpp && meow
meow.cpp
17.00.40214.00
s: "DATA (123) (345 (678) )"
r: "\w+\s*(?:\(((?:[^()]*|\([^()]*\)*)*)\))?\s*(?:\(((?:[^()]*|\([^()]*\)*)*)\))?"
m[0]: "DATA (123) (345 (678) )"
m[1]: "123"
m[2]: "345 (678) "

If you have any further questions, feel free to E-mail me at stl@microsoft.com .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by Microsoft on 2/10/2011 at 1:00 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Sign in to post a workaround.
Posted by prog76 on 2/10/2011 at 9:39 AM
Great. How did you know it?
Big Thanks.
Posted by Viorel_ on 2/10/2011 at 1:29 AM
Change the order of things in 'PROPERTIES_CONTENTS':

// before:
#define PROPERTIES_CONTENTS NON_MATCHING_GROUP(NON_BRACKETS "|" NON_MATCHING_GROUP( "\\(" NON_BRACKETS "\\)*")) "*"

// after:
#define PROPERTIES_CONTENTS NON_MATCHING_GROUP(NON_MATCHING_GROUP( "\\(" NON_BRACKETS "\\)*" ) "|" NON_BRACKETS ) "*"