Skip to content

<regex>: Regex erroneously returns a match #994

Description

Describe the bug
Regex returns a match where it is not expected to return a match.

Note that the pattern has mismatched [ and ].
Need to clarify if it should actually throw, or the behavior is undefined.

Command-line test case

d:\Temp2>type repro.cpp
#include <iostream>
#include <regex>
#include <string>

int main()
{
        try
        {
                std::string Regex = "[[.(.]a[a]";
                std::string MatchString = "v";
                std::regex std_regex(Regex);
                bool Result = std::regex_match(MatchString, std_regex);

                std::cout << "Is matched:" << Result;
        }
        catch (std::regex_error& err)
        {
                std::cout << err.code() << '\n' << err.what() << '\n';
        }
}
d:\Temp2>cl /EHsc /W4 /WX .\repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.27.29009.1 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

repro.cpp
Microsoft (R) Incremental Linker Version 14.27.29009.1
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:repro.exe
repro.obj

d:\Temp2>.\repro.exe
Is matched:1

Expected behavior
DevCom-306176 reporter expects:

Is matched:0

I expect an exception.

STL version

Microsoft Visual Studio Professional 2019 Preview
Version 16.7.0 Preview 3.1

Additional context
Add any other context about the problem here.
This item is also tracked on Developer Community as DevCom-306176 and by Microsoft-internal VSO-660624 / AB#660624.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!regexmeow is a substring of homeowner

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions